Runtime.getRuntime().freeMemory() with ZGC

Mike Rettig mike.rettig at gmail.com
Thu May 27 21:24:39 UTC 2021


How is Runtime.getRuntime().freeMemory() implemented with ZGC? I am using
that value to determine the available heap but it doesn't seem to be
accurate with ZGC.

For example, Runtime.freeMemory() says there are 20gb free, but looking at
the gc logs at the time, ZGC says there should be over 30gb available.
Other times Runtime.freeMemory() reports less than 1mb free, but I know
that isn't true from gc logs and app performance.

Does Runtime.freeMemory() return something other than the available heap
with ZGC?

Thanks,

Mike


More information about the zgc-dev mailing list