語言

GC.CollectionCount(Int32) 方法

定義

回傳指定產生物件時發生的垃圾回收次數。

public:
 static int CollectionCount(int generation);
public static int CollectionCount(int generation);
static member CollectionCount : int -> int
Public Shared Function CollectionCount (generation As Integer) As Integer

參數

generation
Int32

要決定產生哪些物件,該物件被計算為垃圾回收。

傳回

指自程序開始以來,指定世代中垃圾回收發生的次數。

例外狀況

generation 小於0。

備註

如果你自己實作資源管理,可能需要定期透過呼叫 Collect 方法強制垃圾回收。 由於這是一項昂貴的操作,當最近發生垃圾回收時,您可以跳過通話來提升效能。 在呼叫 CollectionCount後立即儲存 的Collect值。 下次你需要打電話 Collect時,將目前 CollectionCount 回傳的數值與已儲存的數值做比較。 若兩個值相等,則表示期間未發生任何收集,且合理地再次呼叫 Collect 。

適用於