简体   繁体   中英

In Java, Heap Memory vs System Memory

I have a java process running on Ubuntu OS, which as per jconsole shows heap memory as 150 MB but for the same process "system monitor" in ubuntu shows approx. 470 MB. Also when I check size of jars in classpath it comes around 200 MB.

I am considering that all jars that are present in classpath will be loaded in JVM for that particular process.

Please can any one help me understand? ... am i missing on something?

Ubuntu system manager is shows totally memory occupied by JRE(Java Runtime Environment). JRE contains other memory such as Stack Memory(Native & Java stacks), Code memory(where java classes and code is present), along with Heap memory. Thus, Heap memory that JConsole will always be less than what it's shown by memory manager. Moreover, JRE manages memory on its own, independent of OS. Thus, it may be possible that It has already acquired more memory from OS, but your program at present is requiring less memory. So, It's holding so that whenever next time your program requires more memory, it doesn't have to go to OS to request for more memory. Because system calls for requesting more memory from OS are expensive.

Coming to your JAR loading question. All the jars, present in your classpath may not be necessarily loaded by your JRE. They'll be loaded on demand basis. Thus, It may happen that there're 100 Jars in your classpath, but only 2 classes in one of the jars are loaded. Thus, those two classes will be loaded in the memory.

For performing more sophisticated memory analysis, I recommend you to use JVisualVM, that comes with several plugins, to analyze memory in the program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM