How is the default max Java heap size determined?

Richard Dorman picture Richard Dorman · Jan 12, 2011 · Viewed 354.5k times · Source

If I omit the -Xmxn option from the Java command line then a default value will be used. According to Java documentation

"the default value is chosen at runtime based on system configuration"

What system configuration settings influence the default value?

Answer

stones333 picture stones333 · Dec 14, 2012

On Windows, you can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.