user2071938
user2071938

Reputation: 2265

"Heap size" is growing way faster than "Used heap"

the Heap size of my java application is continuously growing till it reaches the Max Heap sizeof 1G. Why is that so?

I start my application with those parameters:

java -Xmx1G -XX:+UnlockExperimentalVMOptions \
     -XX:+UseShenandoahGC -XX:ShenandoahUncommitDelay=5000 \
     -XX:ShenandoahGuaranteedGCInterval=10000 - \
     Dlog4j.configurationFile=./log4j2.xml \
     -jar application.jar

Difference of Heap size and Used heap is grwoing

Edit: When I restart my application you see there isn't a gap between "Heap size" and "Used Heap" but this gap is getting bigger and bigger, can I somehow limit that gap?

enter image description here

Upvotes: 2

Views: 1610

Answers (1)

Stephen C
Stephen C

Reputation: 719551

I am not particularly familiar with the way that the new Shenandoah GC normally behaves. However, there is nothing particularly alarming (to me) with that graph.

According to https://shipilev.net/talks/devoxx-Nov2017-shenandoah.pdf, the modus operandi (MO) of a this GC with regards to memory utilization is a bit different to some other collectors.

"We shall take all the memory when we need it, but we shall also give it back when we don’t".

If there is significant load on the allocator (i.e. lots of objects being allocated) Shenandoah will aggressively expand the heap. This is based on the observation that a low-pause GC is most efficient (and most likely to keep up!) if it has plenty of space to work in.

But the flipside is that if your system is idle, the GC will give memory back to the OS more freely than many other GCs.


This seems to fit the memory graph in your question.

The other thing to note is that the heap size (orange) is nowhere near your max-heap limit. If you get close to that limit, the GC will stop growing the heap.

Finally, note that you can apparently encourage Shenandoah to give back uncommitted memory faster by using a smaller value for the -XX:ShenandoahUncommitDelay=<millis> option. However, it is recommended to NOT make it too small because that is liable to slow down the allocator.

(Source: https://www.javacodegeeks.com/2017/11/minimize-java-memory-usage-right-garbage-collector.html)

Upvotes: 2

Related Questions