分代垃圾收集和增量垃圾收集有什么区别?
我认为这两种方法(分代和增量)都是使垃圾收集暂停更快的不同方法。但是分代和增量之间有什么区别呢?它们如何工作?哪一种更适合实时软件/产生更少的长时间停顿?
另外,Boehm GC 是其中之一吗?
I think that both (generational and incremental) are different approaches to make the garbage collection pauses faster. But what are the differences between generational and incremental? How do they work? And which one is better for real time software / produces less long pauses?
Also, the Boehm GC is any of those?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
分代 GC 始终是增量的,因为它不会在一个周期内收集所有无法访问的对象。相反,增量 GC 不一定采用生成方案来决定收集或不收集哪些不可达对象。
分代 GC 大致根据它们的最后一次使用(可以说是它们的年龄)将无法访问的对象划分为不同的集合。基本理论是最近创建的对象很快就会变得无法访问。因此,具有“年轻”对象的集合是在早期阶段收集的。
增量GC可以用上述分代方案来实现,但是可以采用不同的方法来决定应该清除哪组对象。
人们可以查看此维基百科页面并进一步向下,有关两种 GC 方法的更多信息。
根据 Boehm 的网站,他的 GC 是增量式和分代式的:
就实时环境而言,有几篇学术研究论文描述了进行垃圾收集的新颖而巧妙的方法:
A generational GC is always incremental, because it does not collect all unreachable objects during a cycle. Conversely, an incremental GC does not necessarily employ a generation scheme to decide which unreachable objects to collect or not.
A generational GC divides the unreachable objects into different sets, roughly according to their last use - their age, so to speak. The basic theory is that objects that are most recently created, would become unreachable quickly. So the set with 'young' objects is collected in an early stage.
An incremental GC may be implemented with above generational scheme, but different methods can be employed to decide which group of objects should be sweeped.
One might look at this wikipedia page and further downward, for more information on both GC methods.
According to Boehm's website, his GC is incremental and generational:
As far as a real time environment is concerned, there are several academic research papers describing new and ingenious ways to do garbage collection:
增量垃圾收集器是任何可以增量运行的垃圾收集器(意味着它可以做一些工作,然后做更多的工作,然后再做一些工作),而不是必须运行整个收集而无需中断。这与旧的停止世界垃圾收集器形成鲜明对比,旧的垃圾收集器在没有任何其他代码能够在对象上工作的情况下进行标记和清除。但需要明确的是:增量垃圾收集器实际上是否与在同一对象上执行的其他代码并行运行并不重要,只要它是可中断的(为此,它必须区分脏和干净)对象)。
分代垃圾收集器区分旧对象、中对象和新对象。然后,它可以对新对象(关键字“Eden”)进行复制 GC,对旧对象进行标记和清除,并对介质对象进行不同的可能性(取决于实现)。根据实现,区分对象代的方式是通过内存中占用的区域或通过标志。分代 GC 的挑战是保持从一代到另一代引用的对象列表是最新的。
Boem 是一种增量分代 GC,如下所述:http://en.wikipedia.org/wiki/Boehm_garbage_collector
An incremental garbage collector is any garbage-collector that can run incrementally (meaning that it can do a little work, then some more work, then some more work), instead of having to run the whole collection without interruption. This stands in contrast to old stop-the-world garbage collectors that did e.g. a mark&sweep without any other code being able to work on the objects. But to be clear: Whether an incremental garbage collector actually runs in parallel to other code executing on the same objects is not important as long as it is interruptable (for which it has to e.g. distinguish between dirty and clean objects).
A generational garbage collector differentiates between old, medium and new objects. It can then do copying GC on the new objects (keyword "Eden"), mark&sweep for the old objects and different possibilities (depending on implementation) on the medium objects. Depending on implementation the way the generations of objects are distinguished is either by region occupied in memory or by flags. The challenge of generational GC is to keep lists of objects that refer from one generation to the other up to date.
Boem is an incremental generational GC as cited here: http://en.wikipedia.org/wiki/Boehm_garbage_collector
http://www.memorymanagement.org/glossary/i.html#incremental .垃圾.收集
http://www.memorymanagement.org/glossary/g.html# Generational .垃圾.收集
Boehm-Demers-Weiser 具有增量模式,您可以通过调用 GC_enable_incremental 来启用该模式。请参阅 http://www.hpl.hp.com/personal/Hans_Boehm/ gc/gcinterface.html
http://www.memorymanagement.org/glossary/i.html#incremental.garbage.collection
http://www.memorymanagement.org/glossary/g.html#generational.garbage.collection
The Boehm-Demers-Weiser has an incremental mode that you can enable by calling
GC_enable_incremental
. See http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcinterface.html