System.Runtime.InteropServices.Marshal.FinalReleaseComObject Method

Releases all references to a Runtime Callable Wrapper (RCW) by setting its reference count to 0.

Syntax

public static int FinalReleaseComObject (object o)

Parameters

o
The RCW to be released.

Returns

The new value of the reference count of the RCW associated with the o parameter, which is 0 (zero) if the release is successful.

Remarks

The Marshal.FinalReleaseComObject(object) method releases the managed reference to a COM object. Calling this method is equivalent to calling the Marshal.ReleaseComObject(object) method in a loop until it returns 0 (zero).

When the reference count on the COM object becomes 0, the COM object is usually freed, although this depends on the COM object's implementation and is beyond the control of the runtime. However, the RCW can still exist, waiting to be garbage-collected.

The COM object cannot be used after it has been separated from its underlying RCW. If you try to call a method on the RCW after its reference count becomes 0, a System.Runtime.InteropServices.InvalidComObjectException will be thrown.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0