Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Heap Behaviour

Tags:

People also ask

Is heap static or dynamic?

In heap allocation, dynamic data structures and objects are created. 3. In static allocation, the names of the data objects are fixed with storage for addressing. Heap allocation allocates a contiguous block of memory to data objects.

Is Java heap size dynamic?

Heap space is used for the dynamic memory allocation of Java objects and classes at runtime. New objects are always created in the heap space, and references to these objects are stored in the stack memory.

How does heap work in Java?

Java objects reside in an area called the heap. The heap is created when the JVM starts up and may increase or decrease in size while the application runs. When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.

Does Java heap use RAM?

The Java heap lives in RAM (ignoring virtual memory :). You can change the default initial heap size and maximum heap size with the -Xms and -Xmx VM args, respectively.


Given a java memory configuration like the following

 -Xmx2048m -Xms512m

What would be the behaviour of the VM when memory usage increases past 512m? Is there a particular algorithm that it follows? ie. Does it go straight to the max, does it double, does it go in increments, or does it only allocate as it needs memory? How expensive an operation is it?

I'm looking specifically at the Oracle/Sun JVM, version 1.6. I assume this is documented on the Oracle website somewhere, but I'm having trouble finding it.