When does the .NET runtime hold a reference count > 1 for COM objects?
Posted
by Wim Coenen
on Stack Overflow
See other posts from Stack Overflow
or by Wim Coenen
Published on 2010-04-02T14:43:51Z
Indexed on
2010/04/02
15:13 UTC
Read the original article
Hit count: 483
Until recently, I believed that the .NET runtime only increases the reference count of COM objects by 1 when creating a runtime-callable wrapper, and that only one such runtime-callable wrapper is created for any given COM object.
If I'm not mistaken, the above implies that Marshal.FinalReleaseComObject and Marshal.ReleaseComObject do the same thing in practice.
However, today I was writing some tests to verify that COM objects are properly released by my code. I do this by invoking the supposedly released object and checking for the expected InvalidComObjectException
. It turns out that there are cases where the exception is thrown after a FinalReleaseComObject
, but not after a ReleaseComObject
.
Does this mean that the .NET 2.0 runtime can hold more than one reference to a COM object? If so, when does it do this?
© Stack Overflow or respective owner