Hello.
Is there a way of discovering the reference count of a COM object.
e,g. an Excel workbook. ReleaseComObject(xx) decrease the reference count,
but how do I detect if I have missed any references, thus not closing Excel.
Tim
Jay B. Harlow [MVP - Outlook] - 17 Sep 2003 15:56 GMT
Tim,
You can call ReleaseComObject in a loop until it returns zero. Then you are
assured that all the .NET references to the Excel object are released.
This based on what I read about ReleaseComObject in Adam Nathan's book ".NET
and COM - The Complete Interoperability Guide"
Hope this helps
Jay
> Hello.
>
[quoted text clipped - 3 lines]
>
> Tim
Mattias Sj?gren - 17 Sep 2003 16:00 GMT
Tim,
>Is there a way of discovering the reference count of a COM object.
>e,g. an Excel workbook. ReleaseComObject(xx) decrease the reference count,
>but how do I detect if I have missed any references, thus not closing Excel.
Marshal.Release(Marshal.GetIUnknownForObject(obj)) should return the
COM object's reference count.
Note that the RCW usually only increases the COM object refcount by
one, even if you have multiple managed references to the RCW.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.