GCSettings.LargeObjectHeapCompactionMode 屬性

定義

取得或設定值,這個值表示完整的封鎖記憶體回收是否壓縮大型物件堆積 (LOH)。Gets or sets a value that indicates whether a full blocking garbage collection compacts the large object heap (LOH).

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

屬性值

GCLargeObjectHeapCompactionMode

其中一個表示完整封鎖記憶體回收是否壓縮 LOH 的列舉值。One of the enumeration values that indicates whether a full blocking garbage collection compacts the LOH.

屬性

備註

LOH 可用來配置大型物件 (的記憶體,例如需要超過85000個位元組的陣列) 。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.

屬性的預設值 LargeObjectHeapCompactionModeGCLargeObjectHeapCompactionMode.Default ,表示 LOH 不會在垃圾收集期間壓縮。The default value of the LargeObjectHeapCompactionMode property is GCLargeObjectHeapCompactionMode.Default, which indicates that the LOH is not compacted during garbage collections. 如果您將值指派給屬性 GCLargeObjectHeapCompactionMode.CompactOnce ,則會在下一次完整封鎖垃圾收集期間壓縮 LOH,並將屬性值重設為 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. 這表示,如果您將屬性設定 LargeObjectHeapCompactionModeGCLargeObjectHeapCompactionMode.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;
GC.Collect();      
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce
GC.Collect()      

適用於

另請參閱