I have a very simple program which I created just for testing purpose to understand JVM better. My question is during Thread.sleep(...), I saw using JConsole that the program is still using a little bit more than 5 MB of memory. Why is that??
On linux you can always look at all open file handles by calling:
/usr/sbin/lsof | grep java or /usr/sbin/lsof | grep my_java_app's_pid
And you can see all the files loaded into virtual memory. Of course there's a chance that the memory isn't allocated into physical ram, just that it has been internally mapped to the process space.
Just one example of an entry is: java 17120 dchemko mem REG 8,19 50827455 7286804 /usr/java/jdk1.6.0_10/jre/lib/rt.jar
The virtual size of my rt.jar is 50MB, so if the JRE loaded the entire core java classes into memory, you'd be sitting idle at 50MB. Anyways, it is also possible that the system's default minimum stack is set higher than you wanted it to.. or maybe the memory allocated is also reflecting memory mapped files, but I couldn't think of any MMIO files that would open by your setup.
The reason I want to understand better about JVM is because I have a looping program like below. I run it for a while and I saw the heap size keeps increasing and increasing (I use Java VisualVM from Java 6 to analyze the heap). The stack size is constant but not the heap size. I'm trying to figure out why this happen.
is the reason you care about this is because your getting a java.lang.OutOfMemoryError exception? a temporary fix would be to increase the heap size
Even though im marked for death I will spark till i loose my breath
Joined: Oct 13, 2007
I want to understand why the heap size keeps increasing. I don't understand this. I have around another 50+ programs doing similar looping process. If I have to increase the heap size again and again, the amount of memory needed for my server would be huge.
Joined: Oct 13, 2007
Probably this is already a separate question from my original question. I will post a separate question.
Thank you all for your help. I really appreciate it.
subject: Trying to understand better how JVM works.