GCLatencyMode 枚举


调整垃圾收集器侵入应用程序的时间。Adjusts the time that the garbage collector intrudes in your application.

public enum class GCLatencyMode
public enum GCLatencyMode
type GCLatencyMode = 
Public Enum GCLatencyMode


Batch 0

在批调用中禁用垃圾回收并发,并回收对象。Disables garbage collection concurrency and reclaims objects in a batch call. 这是最高级别的侵入模式。This is the most intrusive mode. 此模式专用于最大吞吐量(但以牺牲响应性为代价)。This mode is designed for maximum throughput at the expense of responsiveness.

Interactive 1

在应用程序运行时启用垃圾回收并发,并回收对象。Enables garbage collection concurrency and reclaims objects while the application is running. 这是工作站上垃圾回收的默认模式,并且较少受侵入 BatchThis is the default mode for garbage collection on a workstation and is less intrusive than Batch. 它可以平衡响应性和吞吐量。It balances responsiveness with throughput. 此模式等同于在并发的工作站上执行垃圾回收。This mode is equivalent to garbage collection on a workstation that is concurrent.

LowLatency 2

启用回收对象时比较保守的垃圾回收。Enables garbage collection that is more conservative in reclaiming objects. 仅在系统遇到内存压力时才发生完全回收,而通常情况下发生 0 代和 1 代回收。Full collections occur only if the system is under memory pressure, whereas generation 0 and generation 1 collections might occur more frequently. 此模式不可用于服务器垃圾回收器。This mode is not available for the server garbage collector.

NoGCRegion 4

指示当应用正在执行关键路径时挂起垃圾回收。Indicates that garbage collection is suspended while the app is executing a critical path.

NoGCRegion 是一个只读值;也就是说,不能将 NoGCRegion 值分配给 LatencyMode 属性。NoGCRegion is a read-only value; that is, you cannot assign the NoGCRegion value to the LatencyMode property. 通过调用 TryStartNoGCRegion 方法指定无 GC 区域延迟模式,并通过调用 EndNoGCRegion() 方法终止该模式。You specify the no GC region latency mode by calling the TryStartNoGCRegion method and terminate it by calling the EndNoGCRegion() method.

SustainedLowLatency 3

启用尝试减少延长时期的延迟的垃圾回收。Enables garbage collection that tries to minimize latency over an extended period. 回收器尝试只执行生成 0、生成 1,以及并发只生成 2 个集合。The collector tries to perform only generation 0, generation 1, and concurrent generation 2 collections. 如果系统处于内存压力之下,则完整的阻塞集合还是会出现。Full blocking collections may still occur if the system is under memory pressure.


可以通过将LatencyMode属性设置为除以外GCLatencyMode.NoGCRegion的任何GCLatencyMode枚举值来调整应用程序中垃圾回收的侵入性。You can adjust the intrusiveness of garbage collection in your application by setting the LatencyMode property to any GCLatencyMode enumeration value except GCLatencyMode.NoGCRegion. 还可以通过检索GCSettings.LatencyMode属性值, 确定垃圾回收器的当前延迟模式。You can also determine the garbage collector's current latency mode by retrieving the GCSettings.LatencyMode property value.

有关垃圾回收的运行时配置设置如何影响此枚举的默认值的讨论, 请参阅滞后时间模式See Latency Modes for a discussion of how the runtime configuration settings for garbage collection affect the default value for this enumeration.

模式替代 t > 运行时配置设置。 < GCLatencyMode.BatchThe GCLatencyMode.Batch mode overrides the <gcConcurrent> runtime configuration setting. 如果 <t >元素启用了并发垃圾回收, 则切换到批处理模式会阻止任何其他并发回收。If concurrent garbage collection is enabled by the <gcConcurrent> element, switching to Batch mode prevents any further concurrent collections.