GC Class

GC Class

Developers use the GC class as an interface to the GC in .NET. You can manipulate and monitor garbage collection with the GC class. Some GC commands affect the normal operation of the garbage collection. Garbage collection usefully performs best without developer interference. Table 14-2 lists the static members of the GC class.

Table 14-2: GC Class

Member Name



This property is an integer property and gets the maximum number of generations.


This method forces the GC to recognize memory allocations for unmanaged resources.


This method forces garbage collection on a specific generation. There are two overloads of the method. The no-argument Collect performs garbage collection for all the generations. The one-argument Collect has a parameter that specifies the oldest generation to be collected.


This method returns the number of garbage collection cycles for the specified generation.


This method returns the generation of the specified object.


This method returns the total number of bytes thought to be allocated for the managed heap. You can wait on garbage collection and finalization by setting the Boolean parameter to true.


This method keeps alive the specified object from the beginning of the current routine to where the KeepAlive method is called.


This method removes some of the memory pressure set aside for unmanaged resources.


This method reattaches a finalizer to a resurrected object.


This method suppresses future finalization of the specified object.


This method suspends the current thread until the Finalization queue is empty.