Why make short and long-lived objects a difference in garbage collection?

前端 未结 8 1875
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 19:57

I\'ve often read that in the Sun JVM short-lived objects (\"relatively new objects\") can be garbage collected more efficiently than long-lived objects (\"relatively old obj

8条回答
  •  伪装坚强ぢ
    2020-12-13 20:18

    (see above explanations for more general GC.. this answers WHY new is cheaper to GC than old).

    The reason eden can be cleared faster is simple: the algorithm is proportional to the number of objects that will survive GC in the eden space, not proportional to the number of live objects in the whole heap. ie: if you have an average object death rate of 99% in eden (ie: 99% of objects do not survive GC, which is not abnormal), you only need to look at and copy that 1%. For "old" GC, all live objects in the full heap need to be marked/swept. That is significantly more expensive.

提交回复
热议问题