My code is doing things like this:
for(SomeObject so : someObjects)
{
Blah b = so;
NewObject n = dao.GetNO(b.23);
}
i.e. it is creating a new variable inside the for loop on each iteration.
Could this be the cause of the out of memory issue?
The error reported by Netbeans:
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:133)
at java.lang.StringCoding.decode(StringCoding.java:173)
at java.lang.String.<init>(String.java:443)
at java.lang.String.<init>(String.java:515)
at com.gargoylesoftware.htmlunit.WebResponseImpl.getContentAsString(WebResponseImpl.java:215)
at com.gargoylesoftware.htmlunit.WebResponseImpl.getContentAsString(WebResponseImpl.java:205)
Upate
This is a java console application, and the entire app runs a in forloop basically.
Are you running with Java 5 or greater, or one of the legacy JVM’s? You can try to track down the cause of your OOM by arming your Java command line with -XX:+HeapDumpOnOutOfMemory or attaching to your process with JConsole and requesting a heap dump. You can then use the Eclipse MAT tool to open the dump and view the object graph to see whose holding onto the objects in your program. MAT has a view to see those objects that dominate the object graph – so it becomes extremely clear what exactly is leaking. Looking at the stack trace is not helpful, and can be misleading because a leak in one location of the program can cause a failed allocation somewhere else.