What cause Objects to move from Young Generation to Old Generation

前端 未结 2 723
暖寄归人
暖寄归人 2021-02-15 17:05

After many cycles of GC, Objects that are survived in young generation are moved to the Old generation memory space.

Please clarify, Minor GC is responsible for this ? o

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-15 17:46

    Please clarify, Minor GC is responsible for this ? or Major GC?

    Either of them is responsible for object to move from young gen to old gen.

    Have a look at "General Garbage Collection Process" section @ oracle garbage collection tutorial

    Summary:

    1. First, any new objects are allocated to the eden space. Both survivor spaces start out empty.

    2. When the eden space fills up, a minor garbage collection is triggered

    3. Referenced objects are moved to the first survivor space. Unreferenced objects are deleted when the eden space is cleared.

    4. At the next minor GC, the same thing happens for the eden space. Unreferenced objects are deleted and referenced objects are moved to a survivor space. However, in this case, they are moved to the second survivor space (S1)

    5. At the next minor GC, the same process repeats. However this time the survivor spaces switch. Referenced objects are moved to S0. Surviving objects are aged. Eden and S1 are cleared.

    6. After a minor GC, when aged objects reach a certain age threshold (8 in this example) they are promoted from young generation to old generation.

    7. As minor GCs continue to occur, objects will continue to be promoted to the old generation space.

    8. Eventually, a major GC will be performed on the old generation which cleans up and compacts that space.

提交回复
热议问题