Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When will JVM trigger major garbage collection?

I am trying to understand how garbage collection works. I am clear on the following points:

  1. JVM will trigger minor GC when it fails to allocate objects to the young generation.
  2. List item

JVM will trigger full GC(both minor+major GC) when the heap is full.

But, how about objects in the young generation and old generation which are no longer in reference, eligible for GC, but there is no GC triggered (i.e. young/old generation heap space is not full, thus no GC occurs)

Does that means those objects will remain in young/old generation heap space until a GC occurs?

My reading materials

  • https://plumbr.eu/blog/garbage-collection/minor-gc-vs-major-gc-vs-full-gc

  • http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/

  • https://www.infoq.com/articles/Java_Garbage_Collection_Distilled

like image 502
ilovetolearn Avatar asked Oct 22 '25 03:10

ilovetolearn


2 Answers

it still remains in the old generation and the overall heap usage increases until a full/major GC comes along. The ops team is monitoring the heap usage and they are concerned of the growing heap.

If your goal is monitoring the population of live objects, e.g. to detect leaks, then you should measure heap occupancy immediately after a major GC, not between them.

The information can be extracted from GC log files for example.

JVM will trigger full GC(both minor+major GC) when the heap is full.

This is not necessarily the case. Decisions when to trigger a collection are based on heuristics that take various goals, such as pause times and throughput into account.

like image 193
the8472 Avatar answered Oct 24 '25 19:10

the8472


Yes, if there is no GC then the objects will exist in the heap.

Actually even after GC object will exist in the heap if it is in the young generation, until it will be overwritten, in case of old it depends on the algorithm - but this is interesting only from security standpoint.

like image 38
Krzysztof Krasoń Avatar answered Oct 24 '25 18:10

Krzysztof Krasoń



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!