Release Method
TOC
Collapse the table of content
Expand the table of content

Marshal.Release Method (IntPtr)

 

Decrements the reference count on the specified interface.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

[<SecurityCriticalAttribute>]
static member Release : 
        pUnk:nativeint -> int

Parameters

pUnk
Type: System.IntPtr

The interface to release.

Return Value

Type: System.Int32

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

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 should call Release. Calling Release after the reference count has reached zero causes undefined behavior.

You can call Marshal.GetComInterfaceForObject, Marshal.GetIUnknownForObject, or Marshal.GetIDispatchForObject to obtain an IntPtr value that represents a IUnknown interface pointer to release. You can also use these methods and the Release method on managed objects to release the COM interfaces represented by the managed object's COM Callable Wrapper.

The following example demonstrates how to retrieve an IUnknown interface for a managed object using the GetIUnknownForObject method. The example then releases the interface pointer by calling the Release method.

No code example is currently available or this language may not be supported.

SecurityCriticalAttribute

requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft