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

前端 未结 8 1874
隐瞒了意图╮
隐瞒了意图╮ 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:16

    This is based on the observation that the life-expectancy of an object goes up as it ages. So it makes sense to move objects to a less-frequently collected pool once they reach a certain age.

    This isn't a fundamental property of the way programs use memory. You could write a pathological program that kept all objects around for a long time (and the same length of time for all objects), but this tends not to happen by accident.

提交回复
热议问题