<gcServer > 元素<gcServer> element

指定 Common Language Runtime 是否執行伺服器記憶體回收。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

Common Language Runtime (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 執行的垃圾收集類型。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. 若要使用非並行伺服器垃圾收集,請將gcServer元素設定為 true,並將gcConcurrent 元素設為 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