Monday, 4 February 2019

Useful methods for Garbage Collection.

public static void     AddMemoryPressure(long bytesAllocated)
Indicates that bytesAllocated number of bytes of unmanaged memory have been allocated.
public static void     CancelFullGCNotification( )
Cancels garbage collection notification.
public static void Collect( )
Initiates garbage collection. public static void Collect(int generation) Initiates garbage collection for memory with generation numbers of 0 through generation.
public static void Collect(int generation, GCCollectionMode mode)
Initiates garbage collection for memory with generation numbers of 0 through generation as specified by mode.
public static int CollectionCount(int generation)
Returns the number of garbage collections that have taken place for memory having the generation number specified by generation.
public static int GetGeneration(object obj)
Returns the generation number for the memory referred to by obj.
public static int    GetGeneration(WeakReference wo)
Returns the generation number for the memory referred to by the weak reference specified by wo. A weak reference does not prevent the object from being garbage-collected.
public static long    GetTotalMemory(bool forceFullCollection)
Returns the total number of bytes currently allocated. If forceFullCollection is true, garbage collection occurs first.
public static void KeepAlive(object obj)
Creates a reference to obj, thus preventing it from being garbage-collected. This reference ends when KeepAlive( ) executes.
public static void RegisterForFullGCNotification(int maxGenerationThreshold,  int largeObjectHeapThreshold)
Enables garbage-collection notifications. The value of maxGenerationThreshold specifies the number of generation 2 objects in the normal heap that will trigger notification. The value of largeObjectHeapThreshold specifies the number of objects in the large object heap that will trigger notification. Both values must be between 1 and 99.
public static void RemoveMemoryPressure(long bytesAllocated)
Indicates that bytesAllocated number of bytes of unmanaged memory have been released.
public static void ReRegisterForFinalize(object obj)
Causes the finalizer (i.e., the destructor) for obj to be called. This method undoes the effects of SuppressFinalize( ).
public static void SuppressFinalize(object obj)
Prevents the finalizer (i.e., the destructor) for obj from being called.
public static GCNotificationStatusWaitForFullGCApproach( )
Waits for the notification that a full garbage-collection cycle is about to occur. GCNotificationStatus is an enumeration defined in System.
public static GCNotificationStatusWaitForFullGCApproach(int millisecondsTimeout)
Waits up to millisecondsTimeout milliseconds for the notification that a full garbage-collection cycle is about to occur. GCNotificationStatus is an enumeration defined in System.
public static GCNotificationStatusWaitForFullGCComplete( )
Waits for the notification that a full garbage-collection cycle has completed. GCNotificationStatus is an enumeration defined in System.
public static GCNotificationStatusWaitForFullGCComplete(int millisecondsTimeout)
Waits up to millisecondsTimeout milliseconds for the notification that a full garbage-collection cycle has completed. GCNotificationStatus is an enumeration defined in System.
public static void     WaitForPendingFinalizers( )

Halts execution of the invoking thread until all pending finalizers (i.e., destructors) have been called.

No comments:

Post a Comment