Skip to main content

JVM Memory Usage

Posted by aiqa on April 28, 2005 at 10:29 PM PDT

When JVM spends %98 of it`s time to garbage collections and can not free more then %2 of the memory then an "Out of Memory" exception is thrown. Heap size (the memory space where the progam lives) is calculated according to physical memory. The initial heap size will be set to phys_mem / DefaultInitialRAMFraction. DefaultInitialRAMFraction is a command line option with a default value of 64. Similarly the maximum heap size will be set to phys_mem / DefaultMaxRAM. DefaultMaxRAMFraction has a default value of 4.



With my test machine 64 mb heap memory is not enough to hold as much images as I would like to. I increased memory size with this command line option;



-Xms64m -Xmx256m



This sets the initial and maximum size to 64mb and 256mb. The m suffix can be changed with g to represent gigabyte. You can find java 1.5 command line options here.



Although I set initial memory size to 64 mb, JVM doesn`t allocate 64 mb. When JVM starts it`s memory usage is increased slowly to 12 mb and then garbage collected to 1,5 mb and cycled. When I set initial memory to 4 mb it increased to 2 mb at startup then decreased to ~700 kb and cycled in a longer time period. If you are not sure that your application will use too much memory do not give a big initial memory value, JVM tries to increase memory size for nothing because gc cleans it.



Note: The Java object heap has to be allocated in contiguous virtual addresses, for implementation reasons. In 32 bit operating systems only 2gb memory can be addressed as contiguous.



My personel blog is located at www.projectme.org.

Related Topics >>