Java: how to avoid java.lang.OutOfMemoryError: Java heap space at long run
***** the problem comes up, using the following loop:
int count = 1;
Screen s;
while (true) {
s = new Screen();
System.
s.click(
}
this seems to bind some internal objects, so that GC is not able to free heap memory.
Since this is generally not "good programming" (no need for a new Screen object at each loop turn), the recommended approach does not fill up the heap:
int count = 1;
Screen s = new Screen();
while (true) {
System.
s.click(
}
-------
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.
at sun.reflect.
at sun.reflect.
at sun.reflect.
at java.lang.
at org.eclipse.
der.java:58)
Caused by: java.lang.
at java.awt.
at java.awt.
at java.awt.
n Source)
at java.awt.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at sun.java2d.
at org.sikuli.
35)
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
This question was originally filed as bug #825216.