Memory model

In the Java memory model, the heap memory is divided into a young generation and old generation. The old generation is also known as tenured:

The young generation consists of Eden and Survivor spaces (S0 and S1) and takes up about 40% of the heap memory, while the Old Generation takes up about 60% of the memory.

When the program creates an object, it is created in the Eden space first. When the Eden space is filled up, the partial GC runs, marks the objects that are still referenced, and cleans up the objects in the young generation that are no longer reachable by the program. The following diagram depicts this:

The objects that survive during the partial GC in the Eden space are now promoted to the Survivor space of the young generation. When the Eden space is filled up again, the partial GC runs and reclaims the memory for the objects that are no longer referenced. Any objects that survive during this GC are promoted to the Old Generation.

When the old generation fills up, the full garbage collection runs on the heap memory and deletes the objects that are no longer needed, keeping objects that are referenced by the program. The objects that are likely to live for a long time are moved to the old generation so that the partial GC doesn't have to clean up objects that are still referenced by the program.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset