System.GC.SuppressFinalize Method

Requests that the common language runtime not call the finalizer for the specified object.

Syntax

[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)]
public static void SuppressFinalize (object obj)

Parameters

obj
The object whose finalizer must not be executed.

Exceptions

TypeReason
ArgumentNullException obj is a null reference.
InvalidOperationExceptionThe caller of this method is not the same as the object passed to this method.

Remarks

This method sets a bit in the object header of obj, which the runtime checks when calling finalizers. A finalizer, which is represented by the object.Finalize method, is used to release unmanaged resources before an object is garbage-collected. If obj does not have a finalizer, the call to the GC.SuppressFinalize(object) method has no effect.

Objects that implement the IDisposable interface can call this method from the object's IDisposable.Dispose implementation to prevent the garbage collector from calling object.Finalize on an object that does not require it. Typically, this is done to prevent the finalizer from releasing unmanaged resources that have already been freed by the IDisposable.Dispose implementation.

Requirements

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