[G1]Why run Full GC at System.gc() call?

Andrew Haley aph at redhat.com
Mon Aug 24 09:08:16 UTC 2020

On 24/08/2020 08:22, stefan.johansson at oracle.com wrote:
> One of the few good uses of System.gc() is when you know your
> application doesn't suffer from doing garbage collections, for example,
> you know you have a lot of dead objects and currently no requests you
> have to handle. In this case a full collection is a better fit since it
> will reclaim as much memory as possible, while the concurrent cycle will
> only start reclaiming memory from the old generation in the mixed
> collections that will follow.

Also, you might need some finalizers to be run. This is particularly
important if there are some native resources to be cleaned up. By
definition, the gc doesn't know these resources exist, and they might
be using up all your memory /file handles/ etc.

Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the hotspot-gc-dev mailing list