The GC class publishes services to interface with the garbage collector. You can manipulate and monitor garbage collection with the GC class. While some of the commands provide status information, other GC commands affect the default behavior of garbage collection. Table 17-2 lists the static members of the GC class.
Table 17-2. GC class static members
Member name | Description |
---|---|
MaxGeneration | This property is an integer property and returns the maximum number of generations. |
AddMemoryPressure | This method recognizes memory allocations for unmanaged resources. |
Collect | This method forces garbage collection on a specific generation. There are two overloads of the method. The no-argument Collect does garbage collection on all generations. The one-argument Collect specifies the oldest generation to be collected. |
CollectionCount | This method returns the number of garbage collection cycles for the specified generation. |
GetGeneration | This method returns the generation of the specified object. |
GetTotalMemory | This method returns the total number of bytes allocated for the managed heap. You can wait on garbage collection and finalization by setting the Boolean parameter to true. |
KeepAlive | This method keeps alive the specified object from the beginning of the current routine to where the KeepAlive method is called. |
RemoveMemoryPressure | This method removes some of the memory pressure set aside for unmanaged resources. |
ReRegisterForFinalize | This method reattaches a finalizer to a resurrected object. |
SuppressFinalize | This method suppresses future finalization of the specified object. |
WaitForPendingFinalizers | This method suspends the current thread until the Finalization queue is empty. |
3.142.199.184