Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java heap memory change based on RAM?

I know the default Java heap memory is 128 MB. Since it is the default, I want to know whether this memory get automatically changed according to the RAM size. For an example, for a machine with 128 MB RAM, heap memory 128 is too much and it should be automatically changed. Because if an application use all of 128 heap, PC will end up in a trouble.

please help.

like image 637
PeakGen Avatar asked Aug 04 '26 21:08

PeakGen


1 Answers

In Java 1.6 update 18 (and later), if unspecified, the default heap-size in a client JVM follows these rules:

The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte.

For example, if your machine has 128 megabytes of physical memory, then the maximum heap size is 64 megabytes, and greater than or equal to 1 gigabyte of physical memory results in a maximum heap size of 256 megabytes.

Taken from the 1.6.0_18 update notes

In previous releases of Java heap size was NOT variable by default.

like image 184
Joshua McKinnon Avatar answered Aug 07 '26 13:08

Joshua McKinnon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!