Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of GC does System.gc() trigger?

I have not been able to find the type of GC that System.gc() recommends the JVM to do. Here, it is said that "the System.gc() method ... forces major collections", but this post implies a full gc is requested.

Could anyone clarify or point to documentation that spells this out? In other words, is it a major or full gc that is requested?

like image 692
flow2k Avatar asked Jan 19 '26 13:01

flow2k


1 Answers

That depends on the JVM you're using.

Assuming you're using hotspot the behavior varies based on flags passed to it. By default it triggers a full stop-the-world GC, which will show up as the gc cause [Full GC (System.gc)] in the logs. With DisableExplicitGC it won't invoke any GC at all. If G1 or CMS are used then ExplicitGCInvokesConcurrent will change that behavior to initiate a concurrent old gen collection instead.

The major and minor terminology is not very useful anymore since GC cycles have become more nuanced.

If in doubt, enable GC logging and see for yourself.

like image 83
the8472 Avatar answered Jan 21 '26 05:01

the8472



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!