Mono Class Library: System.GC Overview | Members

System.GC.KeepAlive Method

Creates a reference to the specified object. [Edit]

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

Parameters

obj
A object that is not to be reclaimed by the garbage collector. [Edit]

Remarks

The purpose of the GC.KeepAlive(object) method is to ensure the existence of a reference to an object that is at risk of being reclaimed by the garbage collector prematurely.

The GC.KeepAlive(object) method performs no operations and does not produce any side effects.

This method is required to be implemented in such a way as to prevent optimizing tools from omitting the method call from the executable code.

During program execution, after the call to the GC.KeepAlive(object) method is executed, if there are no additional references to obj in managed code or data, obj is eligible for garbage collection.

[Edit]

Requirements

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