Reputation: 22995
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.
Upvotes: 3
Views: 15524
Reputation: 24709
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.
Upvotes: 8
Reputation: 1604
No. It is not automatically changed. Look here for more on HotSpot JVM memory options .
More Here on handling Java OutOfMemoryError.
Upvotes: 1
Reputation: 8401
You can specify JVM heap size by using aptions -Xmx and -Xms
-Xmx - Max Size. -Xms - Min Size.
You specify like
-Xmx64m -Xms32m (for 64 and 32 MB)
Upvotes: 1
Reputation: 308733
No, it won't be automatically changed unless you ask for it on startup using the -Xmx
option.
You can't get more than 2 GB on a 32 bit machine in any case. If you need more than that, you'll have to get a 64 bit operating system with lots of RAM.
Upvotes: 3