GCSettings.LargeObjectHeapCompactionMode GCSettings.LargeObjectHeapCompactionMode GCSettings.LargeObjectHeapCompactionMode GCSettings.LargeObjectHeapCompactionMode Property


获取或设置指示完全阻止垃圾回收是否压缩大型对象堆 (LOH) 的值。Gets or sets a value that indicates whether a full blocking garbage collection compacts the large object heap (LOH).

 static property System::Runtime::GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode { System::Runtime::GCLargeObjectHeapCompactionMode get(); void set(System::Runtime::GCLargeObjectHeapCompactionMode value); };
[set: System.Security.SecurityCritical]
public static System.Runtime.GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode { get; set; }
member this.LargeObjectHeapCompactionMode : System.Runtime.GCLargeObjectHeapCompactionMode with get, set
Public Shared Property LargeObjectHeapCompactionMode As GCLargeObjectHeapCompactionMode


指示完全阻塞垃圾回收是否压缩 LOH 的枚举值之一。One of the enumeration values that indicates whether a full blocking garbage collection compacts the LOH.


LOH 用于分配的内存需要多个 85,000 个字节的大型对象 (如数组)。The LOH is used for allocating memory for large objects (such as arrays) that require more than 85,000 bytes. 由于复制较大的内存块的性能影响,垃圾回收器通常扫描 LOH,涉及到创建的内存位置的已死对象占用和,可以重复使用,以满足将来请求列表对于大型对象内存的分配。Because of the performance impact of copying large blocks of memory, the garbage collector ordinarily sweeps the LOH, which involves creating a list of the memory locations that were occupied by dead objects and that can be reused to satisfy future requests for allocation of memory for large objects. 但是,在广泛的应用程序中使用的 LOH 来存储临时对象,碎片可能会反过来会影响性能的内存。However, in apps that make extensive use of the LOH to store transient objects, memory fragmentation can also adversely impact performance. 在这种情况下,则可以使用LargeObjectHeapCompactionMode属性压缩而不是只需扫描 LOH 垃圾回收期间。In this case, it is possible to use the LargeObjectHeapCompactionMode property to compact rather than simply sweep the LOH during a garbage collection.

默认值LargeObjectHeapCompactionMode属性是GCLargeObjectHeapCompactionMode.Default,指示在垃圾回收期间不会压缩 LOH。The default value of the LargeObjectHeapCompactionMode property is GCLargeObjectHeapCompactionMode.Default, which indicates that the LOH is not compacted during garbage collections. 如果将属性分配值GCLargeObjectHeapCompactionMode.CompactOnceLOH 压缩在下一步完全阻止垃圾回收,过程和属性值重置为GCLargeObjectHeapCompactionMode.DefaultIf you assign the property a value of GCLargeObjectHeapCompactionMode.CompactOnce, the LOH is compacted during the next full blocking garbage collection, and the property value is reset to GCLargeObjectHeapCompactionMode.Default.


未阻止后台垃圾回收。Background garbage collections are not blocking. 这意味着,如果您设置LargeObjectHeapCompactionMode属性设置为GCLargeObjectHeapCompactionMode.CompactOnce、 随后出现的 2 个集合不会压缩 LOH 任何后台生成。This means that, if you set the LargeObjectHeapCompactionMode property to GCLargeObjectHeapCompactionMode.CompactOnce, any background generation 2 collections that occur subsequently do not compact the LOH. 仅第一个阻止生成 2 个集合会压缩 LOH。Only the first blocking generation 2 collection compacts the LOH.

之后LargeObjectHeapCompactionMode属性设置为GCLargeObjectHeapCompactionMode.CompactOnce,在不确定的未来时间发生的下一个完整的阻碍性垃圾回收 (和 LOH 压缩)。After the LargeObjectHeapCompactionMode property is set to GCLargeObjectHeapCompactionMode.CompactOnce, the next full blocking garbage collection (and compaction of the LOH) occurs at an indeterminate future time. 您可以立即压缩 LOH,通过使用如下代码:You can compact the LOH immediately by using code like the following:

GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce