JVM memory management with the GC
In the following diagrams, we have the heap memory areas, Eden, S0, S1, and Tenured, repeated in the rows numbered 1 to 13 (to the right-hand side of each row). Each row represents how the memory areas look at a certain age time.
Objects allocated in the memory areas are depicted with numbers inside them, denoting the generation or age that they belong to. Generation is a measure of how many times an object has moved from one memory area to another. A generation is complete when a memory area is filled up with objects and needs to move all of its live objects to the next memory area.
In step 1 in the following diagram, objects are being created and hence start to allocate memory in Eden. New data structures always start their lives in Eden, and their generational number is set to 1.
Step 2 shows us more objects allocating room in Eden and some objects that are no longer in use. These are shown in the following diagram as objects...