本文介绍了背景和并发垃圾回收之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了.NET Framework 4的当前垃圾收集实现被替换:

I read that with .NET Framework 4 the current garbage collection implementation is replaced:

.NET框架4提供  后台垃圾收集。本  功能替换并发垃圾  收集previous版本和  提供更好的性能。

此页面有一个解释,它是如何的作品,但我不知道我的理解它。

At this page there is an explanation how it works but I am not sure I understood it.

在实际的应用程序中这个又是什么新的GC实现的效益?它是一个功能,该功能可以使用,以推动从3.5或previous过渡到4.0?

In practical world application what is the benefit of this new GC implementation? Is it a feature that could be use to push for a transition from 3.5 or previous to 4.0?

推荐答案

在这里,微软使用的名称并发和背景来形容两个版本它使用.NET的GC的。在.NET世界中,背景集电极是增强过来的并发收集,因为它具有较少的限制什么应用程序线程可以收集运行时做

Here, Microsoft uses the names "concurrent" and "background" to describe two versions of the GC it uses in .NET. In the .NET world, the "background collector" is an enhancement over the "concurrent collector" in that it has less restrictions on what application threads can do while the collector is running.

有一个基本的GC采用了停了世界的战略:应用性的线程分配的内存块从一个共同的堆。当GC必须运行(如过多的块已被分配,一些清理是必要的),所有的应用性(管理)的线程停止。最后停止线程运行的GC和放开所有其他线程时,它已经完成了。一个停止这世界GC实现起来很简单,但导致暂停可在用户级别察觉。

A basic GC uses a "stop-the-world" strategy: applicative threads allocate memory blocks from a common heap. When the GC must run (e.g. too many blocks have been allocated, some cleanup is needed), all applicative (managed) threads stop. The last stopping thread runs the GC, and unblocks all the other threads when it has finished. A stop-the-world GC is simple to implement but induces pauses which can be perceptible at the user level.

微软的并发GC是世代:它使用的停止的世界战略堆的只是有限的一部分(他们称之为代0和1)。因为该部分仍然很小,暂停保持短(例如50毫秒以下),以使用户不会注意到他们。堆的其余部分被收集用专用的GC螺纹,它可以运行的同时的与应用性螺纹(因此而得名)。

Microsoft's "concurrent GC" is generational: it uses the stop-the-world strategy for only a limited part of the heap (what they call "generations 0 and 1"). Since that part remains small, pauses remain short (e.g. below 50ms), so that the user will not notice them. The rest of the heap is collected with a dedicated GC thread, which can run concurrently with the applicative threads (hence the name).

并发GC有一定的局限性。也就是说,有时刻,当GC线程必须承担起堆了几分独特的控制。在这样的时代,应用性线程只能从小线程特定区域分配块。它有更大的需求线程在主堆,其中,当时,由GC线程锁定很快就会跌倒。该分配线程必须再阻塞,直到GC线程完成其锁定的堆阶段。这再次引起暂停。少停顿比具有停止的世界GC和这些停顿不会影响所有线程。然而,仍然暂停。

The concurrent GC has some limitations. Namely, there are moments when the GC thread must assume a somewhat exclusive control of the heap. During such times, applicative threads may allocate blocks only from small thread-specific areas. Threads which have bigger needs will soon stumble upon the main heap, which, at that time, is locked by the GC thread. The allocating thread must then block until the GC thread has finished its lock-the-heap phase. This again induces pauses. Less pauses than with a stop-the-world GC, and these pauses do not affect all threads. Yet pauses nonetheless.

背景气相色谱法是一种增强型气相色谱中的GC线程需要不锁堆。这消除了在previous段所述的额外暂停;仅停留在有限的暂停,当年轻一代收集(微软称之为前台集)。

The "background GC" is an enhanced GC in which the GC thread needs not lock the heap. This removes the extra pauses described in the previous paragraph; only remain the limited pauses when the young generations are collected (what Microsoft calls "a foreground collection").

注意:有隐性成本与并发GC和GC背景。对于这些GC正常运行,内存访问的应用性线程必须在一些非常具体的方式,这对性能有轻微的影响来完成。另外,在GC线程可能对高速缓冲存储器有不利的影响,从而间接地降低性能。对于无需用户交互纯粹的计算任务,停止这世界署长可的平均的,产量有所提高性能(例如,一个二十小时长的计算将在nineteen小时内完成) 。但是,这是一个边缘的情况下,和在大多数情况下同时和背景的GC也较好。

Note: there are "hidden costs" with the concurrent GC and the background GC. For these GC to operate properly, memory accesses from applicative threads must be done in some very specific ways, which have a slight impact on performance. Also, the GC thread may have an adverse effect on cache memory, thus indirectly degrading performance. For a purely computational task with no need for user interaction, a stop-the-world collector may, on average, yield somewhat better performance (e.g. a twenty-hours-long computation will complete in nineteen hours). But this is an edge case, and in most situations the concurrent and background GC are better.

这篇关于背景和并发垃圾回收之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:43