Collection Count(Int32) 方法
返回已经对对象的指定代进行的垃圾回收次数。Returns the number of times garbage collection has occurred for the specified generation of objects.
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
对象的代，将针对此代确定垃圾回收计数。The generation of objects for which the garbage collection count is to be determined.
自启动进程以来已经对指定代进行的垃圾回收次数。The number of times garbage collection has occurred for the specified generation since the process was started.
generation 小于 0。
generation is less than 0.
如果实现自己的资源管理，则可能需要通过调用 Collect 方法来定期强制进行垃圾回收。If you implement your own resource management, you might need to force garbage collection periodically by calling the Collect method. 由于这是一种代价高昂的操作，因此可以通过在最近发生垃圾回收时跳过调用来提高性能。Because this is an expensive operation, you can improve performance by skipping the call when a garbage collection has occurred recently. Collect调用后立即保存 CollectionCount 返回的值。Save the value returned by CollectionCount immediately after calling Collect. 下次需要调用 Collect时，请将 CollectionCount 返回的当前值与保存的值进行比较。The next time you need to call Collect, compare the current value returned by CollectionCount to the saved value. 如果这两个值相等，则说明中间没有出现任何集合，因此再次调用 Collect 是合理的。If the two values are equal, no collection has occurred in the interim and it is reasonable to call Collect again.