Usually I set -Xms512m
and -Xmx1g
so that when JVM starts it allocates 512MB and gradually increases heap to 1GB as necessary. But I see these values s
From Oracle Java SE 8 docs:
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/sizing.html By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters
-XX:MinHeapFreeRatio=
and-XX:MaxHeapFreeRatio=
, and the total size is bounded below by -Xms
and above by-Xmx
. Setting-Xms
and-Xmx
to the same value increases predictability by removing the most important sizing decision from the virtual machine. However, the virtual machine is then unable to compensate if you make a poor choice.
if the value of -Xms and -Xmx is same JVM will not have to adjust the heap size and that means less work by JVM and more time to your application. but if the chosen value is a poor choice for -Xms then some of the memory allocated will never be used because the heap will never shrink and if it is a poor choice for -Xmx you will get OutOfMemoryError.