Marshal.FinalReleaseComObject(Object) Method

Definition

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

C#
[System.Security.SecurityCritical]
public static int FinalReleaseComObject(object o);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static int FinalReleaseComObject(object o);
C#
public static int FinalReleaseComObject(object o);

Parameters

o
Object

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.

Attributes

Exceptions

o is not a valid COM object.

Remarks

The FinalReleaseComObject method releases the managed reference to a COM object. Calling this method is equivalent to calling the ReleaseComObject 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 InvalidComObjectException will be thrown.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

See also