java - 世代垃圾收集

标签 java garbage-collection

据我了解,分代GC将对象分成几代。
并且在每个周期中,GC 只运行一代。

为什么?为什么垃圾收集只有一代就足够了?

P.S: 我从 here 了解所有这些.

最佳答案

如果您阅读 link我在 earlier question you had about Generational GC 中提供,你就会明白为什么会这样了,这个循环就是white set内存被填满的时候。

To optimize for this scenario, memory is managed in generations, or memory pools holding objects of different ages. Garbage collection occurs in each generation when the generation fills up. Objects are allocated in a generation for younger objects or the young generation, and because of infant mortality most objects die there. When the young generation fills up it causes a minor collection. Minor collections can be optimized assuming a high infant mortality rate. The costs of such collections are, to the first order, proportional to the number of live objects being collected. A young generation full of dead objects is collected very quickly. Some surviving objects are moved to a tenured generation. When the tenured generation needs to be collected there is a major collection that is often much slower because it involves all live objects.

基本上,每个对象都分为几代(基于关于对象的假设)并将它们放入特定代的内存堆中。当该内存堆被填满时,GC 周期开始,那些仍然引用的对象被移动到另一个内存堆并添加新对象。

关于java - 世代垃圾收集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5491682/

相关文章:

java - spring boot、logback 和 logging.config 属性

java - 使用postgres和java执行sql查询时内存泄漏

garbage-collection - Gambit-C 的 GC 机制是什么?

c# - 为什么带有终结器的类需要不止一个垃圾回收周期?

java - 在什么情况下,年轻一代的java垃圾回收会持续很长时间?

java - 如何正确使用 JTI 声明和 JWT 来防止重放攻击?

java - 使用随机生成的数字读取数组

java - Wicket 7 - 向导完成按钮生成多个 onClick 事件

java - 在jsp页面显示1000条记录

python - 调试 Python fatal error : GC Object already Tracked