This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am facing a problem of java heap size .( memory out of ) . my all java class are singleton and method have local variables ,
Method local variables are four Map and two List . I call method by class instance on a jsp page with continuous ajax call with some another page. ..
after some time (mostly 5 hours)..i got jvm out of memory heap size error. I have alloted 64 MB memory to my tomcat .
When I used jProfiler for jvm memory hotspot , I found size of all variables increases exponentially .
please suggest how to optimize this jvm heap size error.
should i use some another design pattern and data structure. ?
Out Of Memory error can come because of two reasons:
Application has such a number of in-use objects, the size of which is greater than the allocated heap size.
There is a memory leak
In the first case, increasing the heap size will be effective.
On the other hand, increasing the heap size will be a temporary solution as the memory leak will somehow kill the application sooner or later.
So, you need to find out whether you have memory leaks in your application. If yes, then you need to fix them rather than increasing heap size.
Deepak Rajkiran wrote:
my all java class are singleton and method have local variables ,
Method local variables are four Map and two List . I call method by class instance on a jsp page with continuous ajax call with some another page
* I am just suggesting to double check your singleton code ... may be its not working as a singleton ... so i would suggest to put some kind of System.out.println() in the constructor of your singleton or use a logger to log this information. so that you we be sure that only one object is created.
* I don't know what type of data you are storing in your maps and lists, however may be there is a possibility that you keep adding new objects even if in some cases there is no need to add them, it would be a good idea to clean your maps and lists from unnecessary data.
except that i don't know may be your application really needs a bigger heap size.
Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
It does sound like you might have a memory leak. If you are using JDK 6, the [url=https://visualvm.dev.java.net/]VisualVM[url] can help you track down the memory leak - you can take two memory snapshots a few minutes apart and compare them - it will show you what objects increased in number. This can help you isolate the issue. (I know VisualVM can monitor JDK 5 apps, but I don't recall if you can get the heap snapshot.)