Reputation: 2265
the Heap size
of my java application is continuously growing till it reaches the Max Heap size
of 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
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?
Upvotes: 2
Views: 1610
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