Why does Java use a static heap and not allow an arbitrary amount of memory?

In Java, a virtual machine preallocates a bunch of memory that cannot be expanded at run time. A developer can increase the heap size with the -Xmx switch when loading the VM, but there is no way to increase the maximum heap size at run time. Why is this?

+4
source share
3 answers

There is no reason in the JVM specification why heap size should be specified in advance, except that it was the choice of the developers. The specification states: "The implementation of the Java Virtual Machine can give the programmer or user control over the initial heap size, and if the heap can be dynamically expanded or reduced, control the maximum and minimum heap size."

The other answers here are simply incorrect: "The heap can have a fixed size or can be expanded as required by the calculation, and can be reduced if a large heap becomes unnecessary."

Source: Java Virtual Machine Specification, Java SE 7 Version. Section 2.5.3, “Heap”. This is page 13 of the print edition.

+7
source

- , . , , . , , ( , @mttdbrd), .

Java, 1 , , 256 , ! , , , , . , , , () .

, , , , , , .

, , , , , , , Java- , , .

, , .

+9

, JVM . , , , , , .;)

+1

Source: https://habr.com/ru/post/1533769/


All Articles