Runtime.getRuntime().freeMemory() with ZGC

Mike Rettig mike.rettig at
Thu Jun 3 13:44:50 UTC 2021

On Thu, Jun 3, 2021 at 5:01 AM Per Liden <per.liden at> wrote:

> If I understand your use case correctly, it sounds like the option you
> are looking for is -XX:ZCollectionInterval=<seconds>. This tells ZGC to
> do a GC at least every <seconds> (where <seconds> can be floating point
> number). Since pauses are O(1), this effectively means the same thing as
> "target pause frequency" or "target accumulated pause time per minute"
> but specified in a different way. ZGC would only collect garbage more
> often than ZCollectionInterval if it has already grown the heap to its
> max size and it's still not enough to avoid an allocation stall.
> However, under "normal conditions" it will grow/shrink the heap to a
> size that is enough to meet the ZCollectionInterval goal.
> /Per

My preference is for a "max" number of collections. If I specified the
interval then that would be a min with the actual number of collections
being scheduled + high usage + proactive. However if I disable proactive
then it might be close enough to what I want but it depends on how "High
Usage" collections work. Do "High Usage" collections only consider the
overall max heap (-Xmx) and not the current heap?  If the answer is -Xmx
then it is probably okay, but if it is the current heap then the scheduled
collections are similar to proactive collections in that they just add
unnecessary collections.


More information about the zgc-dev mailing list