<gcServer > 元素<gcServer> Element

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

<configuration><configuration>
<运行时 ><runtime>
<gcServer><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. 使用 <gcServer> 元素以控制 CLR 执行的垃圾回收类型。You 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.

此元素只能在应用程序配置文件中使用;如果此元素在计算机配置文件中,请忽略。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.NET Framework 4.5 起,服务器垃圾回收就是并发回收。Starting with the .NET Framework 4.5.NET Framework 4.5, server garbage collection is concurrent. 若要使用非并发服务器垃圾回收,设置<gcServer>元素true <gcConcurrent > 元素falseTo use non-concurrent server garbage collection, set the <gcServer> element to true and the <gcConcurrent> element to false.

示例Example

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

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

请参阅See also