System.Runtime.InteropServices.Marshal.Release Method

Decrements the reference count on the specified interface.

Syntax

[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)]
public static int Release (IntPtr pUnk)

Parameters

pUnk
The interface to release.

Returns

The new value of the reference count on the interface specified by the pUnk parameter.

Remarks

The common language runtime manages the reference count of a COM object for you, making it unnecessary to use this method directly. Use this value only for testing purposes. In rare cases, such as testing a custom marshaler, you might find it necessary to manipulate an object's lifetime manually. Only programs that call Marshal.AddRef(IntPtr) should call Marshal.Release(IntPtr). Calling Marshal.Release(IntPtr) after the reference count has reached zero causes undefined behavior.

You can call Marshal.GetComInterfaceForObject(object, Type), Marshal.GetIUnknownForObject(object), or Marshal.GetIDispatchForObject(object) to obtain an IntPtr value that represents a tp://go.microsoft.com/fwlink/?LinkId=148003 interface pointer to release. You can also use these methods and the Marshal.Release(IntPtr) method on managed objects to release the COM interfaces represented by the managed object's COM Callable Wrapper.

Requirements

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