Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 779
Eugene_Z Avatar asked Jul 24 '19 15:07

Eugene_Z


People also ask

How does garbage collector know which objects to free?

When the garbage collector performs a collection, it releases the memory for objects that are no longer being used by the application. It determines which objects are no longer being used by examining the application's roots.

How does Java know when to garbage collect a reference?

As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.

How GC decides if objects are live in C#?

How GC decides if objects are live? GC checks the below information to check if the object is live: It collects all handles of an object that are allocated by user code or by CLR. Keeps track of static objects, as they are referenced to some other objects.

When a GC occurs in old gen area it is known as a full GC?

A Full GC will be triggered whenever the heap fills up. In such a case the young generation is collected first followed by the old generation.


1 Answers

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

like image 175
Turac Avatar answered Nov 03 '22 20:11

Turac