← Back to team overview

sikuli-driver team mailing list archive

[Bug 825216] Re: X-1.0-rc3: Java: java.lang.OutOfMemoryError: Java heap space at long run

 

Hi Raiman,

I resolved the problem by optimizing my code. Initially the code was
like this:

public static void main(String[] args) throws FindFailed {
		
		
		int count = 1;
		Screen s;
		while (true) {
			s = new Screen();
			System.out.println("Count = "+ count++);
			s.click("start.png", 0);
		}
	}

I exported this as a jar file and I ran it with default heap space of
JVM. It gave me "OutOfMemoryError" after around 60 iterations.

Then I modified the above code the following way:

public static void main(String[] args) throws FindFailed {
		
		
		int count = 1;
		Screen s;
		while (true) {
			s = Sikuli.getScreen();
			System.out.println("Count = "+ count++);
			s.click("start.png", 0);
		}
	}

/** A Singleton class for {@link Screen} */
public class Sikuli {
	private static Screen s;
	private static boolean IS_INSTANCE_AVAILABLE = false;
	
	public static Screen getScreen(){
		if (IS_INSTANCE_AVAILABLE == true) {
			return s;
		} else {
			s = new Screen();
			IS_INSTANCE_AVAILABLE = true;
			return s;
		}
	}

}

After making this modifications, when I exported this as jar file and
ran with default heap space, it ran perfectly without giving any
"OutOfMemoryError"..

Ideally, if I instantiate the "Screen" class many times within the scope
of an application, the JVM should take care of those instances which are
going out of scope. Hence, in the first sample of code as well, it was
not expected to get "OutOfMemoryError".

But my problem got resolved as of now.

Thanks
Anirban

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/825216

Title:
  X-1.0-rc3: Java: java.lang.OutOfMemoryError: Java heap space at long
  run

Status in Sikuli:
  New

Bug description:
  I am running sikuli script from Java program in Win XP 32 bit
  platform. While running the same script iteratively for long time I am
  getting the "OutOfMemory" error which I suspect is because of the
  memory leak problem of sikuli.

  While running a simple script, I set the heap space of JVM to 1GB.
  With that, a simple script having 4 calls to API "click" and one call
  to API "exists", ran for around 2 hours and gave the following
  exception:

  Exception in thread "main" java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
  der.java:58)
  Caused by: java.lang.OutOfMemoryError: Java heap space
          at java.awt.image.DataBufferInt.<init>(Unknown Source)
          at java.awt.image.Raster.createPackedRaster(Unknown Source)
          at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknow
  n Source)
          at java.awt.image.BufferedImage.<init>(Unknown Source)
          at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
          at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
          at sun.java2d.loops.MaskBlit$General.MaskBlit(Unknown Source)
          at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Unknown Source)
          at sun.java2d.pipe.DrawImage.blitSurfaceData(Unknown Source)
          at sun.java2d.pipe.DrawImage.renderImageCopy(Unknown Source)
          at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
          at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
          at sun.java2d.pipe.ValidatePipe.copyImage(Unknown Source)
          at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
          at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
          at org.sikuli.script.OpenCV.convertBufferedImageToByteArray(OpenCV.java:
  35)
          at org.sikuli.script.OpenCV.convertBufferedImageToMat(OpenCV.java:41)
          at org.sikuli.script.Finder.<init>(Finder.java:70)
          at org.sikuli.script.Region.doFind(Region.java:965)
          at org.sikuli.script.Region$RepeatableFind.run(Region.java:1168)
          at org.sikuli.script.Region$Repeatable.repeat(Region.java:1139)
          at org.sikuli.script.Region.wait(Region.java:453)
          at org.sikuli.script.Region.find(Region.java:333)
          at org.sikuli.script.Region.getLocationFromPSRML(Region.java:1065)
          at org.sikuli.script.Region.click(Region.java:562)

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/825216/+subscriptions


References