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 是合理的。

适用于