6

Minor GC - when garbage collectors clears objects in the young generation which are not referenced from the "roots". Minor GC works on young heap only. But what if a young object is referenced from the old heap?

trincot
  • 317,000
  • 35
  • 244
  • 286
Eugene_Z
  • 235
  • 2
  • 12
  • https://stackoverflow.com/a/47505987/2711488 • https://stackoverflow.com/a/3849058/2711488 – Holger Jul 24 '19 at 17:06

2 Answers2

5

Garbage Collector needs know old objects that refer to young objects. To find all these references, it can scan all old objects but it is very bad solution. So Remembered set keeping this information . Each thread then informs the GC if it changes a reference, which could cause a change in the remember set.

A card table(array of bytes) is a particular type of remembered set. If reference changed, card (Each byte is referred to as a card in card table) gets dirty. Dirty card contain new pointer from the old generation to the young generation. Finally java not scan all old object, instead of scan remembered set.

GC1 Card Table and Remembered Set

Marking card

Turac
  • 667
  • 1
  • 4
  • 19
2

Minor GC will collect the young generation but it doesn't mean that the GC will look only at the young generation heap area. The entire heap is considered and a reference from old generation to young generation will mark the object in young generation as alive.

This is described in Minor GC vs Major GC vs Full GC:

During a Minor GC event, Tenured generation is effectively ignored. References from tenured generation to young generation are considered de facto GC roots. References from young generation to Tenured generation are simply ignored during the markup phase.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111