<r > 元素<gcServer> element

指定公共语言运行时是否运行服务器垃圾回收。Specifies whether the common language runtime runs server garbage collection.

<configuration><configuration>
  <运行时 >  <runtime>
    <r >    <gcServer>

语法Syntax

<gcServer
   enabled="true|false"/>

特性和元素Attributes and elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
enabled 必需的特性。Required attribute.

指定运行时是否运行服务器垃圾回收。Specifies whether the runtime runs server garbage collection.

enabled 属性enabled attribute

“值”Value 描述Description
false 请勿运行服务器垃圾回收。Does not run server garbage collection. 这是默认设置。This is the default.
true 运行服务器垃圾回收。Runs server garbage collection.

子元素Child elements

无。None.

父元素Parent elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有关程序集绑定和垃圾回收的信息。Contains information about assembly binding and garbage collection.

备注Remarks

公共语言运行时 (CLR) 支持两种类型的垃圾回收:工作站垃圾回收(适用于所有系统)和服务器垃圾回收(适用于多处理器系统)。The common language runtime (CLR) supports two types of garbage collection: workstation garbage collection, which is available on all systems, and server garbage collection, which is available on multiprocessor systems. 使用r元素可控制 CLR 执行的垃圾回收的类型。Use the gcServer element to control the type of garbage collection the CLR performs. 使用 GCSettings.IsServerGC 属性以确定是否启用服务器垃圾回收。Use the GCSettings.IsServerGC property to determine if server garbage collection is enabled.

对于单处理器计算机,默认的工作站垃圾回收应该是最快捷的选项。For single-processor computers, the default workstation garbage collection should be the fastest option. 对于双处理器计算机,最快捷的选项既可以是工作站垃圾回收又可以是服务器垃圾回收。Either workstation or server can be used for two-processor computers. 对于两个以上处理器的计算机,服务器垃圾回收应该是最快捷的选项。Server garbage collection should be the fastest option for more than two processors. 在同一台计算机上运行多个服务器应用实例时,最常见的多处理器服务器系统禁用服务器 GC 并使用工作站 GC。Most commonly, multiprocessor server systems disable server GC and use workstation GC instead when many instances of a server app run on the same machine.

此元素只能在应用程序配置文件中使用;如果此元素在计算机配置文件中,请忽略。This element can be used only in the application configuration file; it is ignored if it is in the machine configuration file.

备注

在 .NET Framework 4 和更低版本中,启用服务器垃圾回收之后,并发垃圾回收不可用。In the .NET Framework 4 and earlier versions, concurrent garbage collection is not available when server garbage collection is enabled. 从 .NET Framework 4.5 开始,服务器垃圾回收将并发执行。Starting with the .NET Framework 4.5, server garbage collection is concurrent. 若要使用非并发服务器垃圾回收,请将r元素设置为 true,并将t 元素设置为 falseTo use non-concurrent server garbage collection, set the gcServer element to true and the gcConcurrent element to false.

从 .NET Framework 4.6.2 开始,你还可以使用以下元素来配置服务器 GC:Starting with .NET Framework 4.6.2, you can also use the following elements to configure server GC:

  • GCNoAffinitize,用于指定服务器 GC 堆与处理器之间是否存在关联。GCNoAffinitize, which specifies whether there is an affinity between server GC heaps and processors. 默认情况下,每个处理器都有一个服务器 GC 堆。By default, there is one server GC heap for each processor.

  • GCHeapCount,用于限制进程使用的堆数。GCHeapCount, which limits the number of heaps used by a process.

  • GCHeapAffinitizeMask,用于定义可用服务器 GC 堆和单个处理器之间的关联。GCHeapAffinitizeMask, which defines the affinity between the available server GC heaps and individual processors.

示例Example

下面的示例启用服务器垃圾回收:The following example enables server garbage collection:

<configuration>
   <runtime>
      <gcServer enabled="true"/>
   </runtime>
</configuration>

请参阅See also