How GC knows if object in old heap references an object in young heap?

Eugene_Z :

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?

Karol Dowbecki :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=126155&siteId=1