Generation 0 is youngest generation and contains short-lived objects. All newly created objects are contained in generation 0. Garbage collection occurs more frequently in this generation. If there is no memory in generation 0, they are promoted to generation 1.
Generation 1 acts as a buffer between short-lived and long-lived objects, it contains short-lived objects.
Generation 2 contains long lived objects.
A garbage collection has the following phases:
- A marking phase will find and create a list of all live objects.
- A relocating phase will update the references to the objects that will be compacted.
- A compacting phase will reclaim the space occupied by the dead objects and will compact the surviving objects. The compacting phase will move objects that have survived a garbage collection toward the older end of the segment.
Collecting a generation means collecting objects in that generation and all its younger generations.
No comments:
Post a Comment