javaheap-memoryvisualvm

Understanding the relationship between Max Heap size, Heap size and Used heap


For this application, -Xmx64m is allocated (the same can be seen from the chart from VisualVM). However, it is not clear what exactly these areas mean in the context of memory allocation to this application.

I can imagine what the maximum allocation for heap means - the maximum value beyond which heap will not grow. I can also understand what heap utilised means - the currently occupied area (blue area).

But what is the ‘Heap size’ in the orange area? It's not max, it's almost halved, and what does it mean?

In the end, how to interpret this graph (i.e. these values) in the context of performance (or memory sufficiency) for this application?

(Those peak areas in the middle correspond to the active phase of the application, the rest correspond to the idle phase.)

enter image description here


Solution

  • But what is the ‘Heap size’ in the orange area? It's not max, it's almost halved, and what does it mean?

    Heap memory is dynamic in JVM, meaning it can increase or decrease. The orange area shows to you in some specific point of time how large heap memory was. Example in time 19:00 according to your diagram the heap was at ~35MB. Inside this allocated heap memory you can see in the blue area the size which was actually used which in that point of time was ~14MB.

    In case the application continued to need more memory, the JVM would have increased the heap size and it would have went to a size bigger than 35MB (orange area) but according to your JVM configuration -Xmx64m it would not be able to go bigger than 64MB.

    Essentialy the heap (orange area) is some memory that JVM has communicated to OS that is required and OS has already allocated this memory for JVM either in physical or virtual memory and is currently available for use.