In my Tomcat application I am eventually getting “Out of memory” and “Cannot allocate memory” errors. I suppose it is nothing to do with the heap as it completely fulls up the system memory and I am hardly able to run bash commands.
How this problem is connected to the heap? How can I correctly set up heap size so that the application has enough memory and so it does not consume too much of the system resources?
Strange thing is that “top” command keeps saying that tomcat consumes only 20% of mem and there is still free memory, once the problem happens.
Thanks.
EDIT:
Follow-up:
BufferedImage leaks – are there any alternatives?
Problems with running bash scripts may indicate
I/Oissues, and this might be the case if your JVM is doing Full GCs all the time (which is the case, if your heap is almost-full).The first thing to do, is to increase the heap with
-Xmx. This may solve the problem, or – if you have a memory leak, it won’t, and you will eventually getOutOfMemoryErroragain.In this case, you need to analyze memory dumps. See my answer in this thread for some instructions.
Also, it might be useful to enable Garbage Collection Logs (using
-Xloggc:/path/to/log.file -XX:+PrintGCDetails) and then analyzing them with GCViewer or HPJmeter.