System.GC.RegisterForFullGCNotification Method

Specifies that a garbage collection notification should be raised when conditions favor full garbage collection and when the collection has been completed.

Syntax

public static void RegisterForFullGCNotification (int maxGenerationThreshold, int largeObjectHeapThreshold)

Parameters

maxGenerationThreshold
A number between 1 and 99 that specifies when the notification should be raised based on the objects surviving in generation 2.
largeObjectHeapThreshold
A number between 1 and 99 that specifies when the notification should be raised based on objects allocated in the large object heap.

Remarks

If you have situations in which a full garbage collection by the common language runtime would adversely affect your application's performance, you can determine whether the runtime is about to induce a full garbage collection and circumvent that collection by inducing a collection yourself (using the GC.Collect method) when conditions are still favorable. For more information about what represents a full garbage collection, see Garbage Collection Notifications.

When you register for a garbage collection notification, you can determine whether the event that signals an approaching full garbage collection has been raised by checking the status of the garbage collection notification. This pattern resembles how the operating system monitors for low memory notifications.

Use the following guidelines for specifying the maxGenerationThreshold and largeObjectHeapThreshold parameters:

  • The larger the threshold value, the further away in time the collection will likely occur and the sooner the notification will be raised.

    A larger threshold value provides more opportunities for the runtime to check for an approaching collection. This increases the likelihood that you will be notified. However, you should not set the threshold too high because that results in a longer wait before the runtime induces the next collection.

    When you induce a collection yourself upon notification using a high threshold value, more objects are reclaimed than would be reclaimed by the runtime's next collection.

  • The smaller the threshold value, the greater the likelihood that a collection will occur sooner and the notification will be raised later.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 4.0.0.0