246. Tracing the generational GC process
In this problem, let’s start from an arbitrary initial state of a generational GC and follow a few hypothetical epochs (generally, all generational GC works more or less as you’ll see in this problem). We start with the following diagram:
Figure 12.2: GC initial state
At its initial state, the GC has an almost full Eden space (it stores objects 1, 4, 5, 2, 6, and 3, and some free space – represented by those white gaps between objects) and empty Survivor and Tenured spaces. Moreover, object 7 should be added in the Eden space but there is not enough memory for it. When the Eden space cannot accommodate more objects, the GC triggers a MinorGC event. First, the non-live objects are identified. Here (as you can see in the following diagram), we have three objects (5, 2, and 3) that should be collected as garbage:
Figure 12.3: Identify the non-live objects from the Eden space
These three objects are...