Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

Reference Count.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim Marsden - 17 Sep 2003 14:29 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.