logo       

Re: should i treat COM Objects as IDisposeable things: msg#00088

windows.devel.dotnet.cx

Subject: Re: should i treat COM Objects as IDisposeable things

Furthermore, the ref count on an RCW can be more than 1. Call
ReleaseComObject() only decrements the ref count 1 time and unless the
ref count goes to 0, the COM object hangs around. See Adam Nathan's
COM/NET interop book pg 300 for reasons for this. Because of this, I
typically do:

if (_comObject != null)
while (Marshal.ReleaseComObject(_comObject) > 0);

For Whidbey, MS has provided a new method in Marshal to do the loop
above for you. It is called FinalReleaseComObject method.

BTW, Adam once told me that calling ReleaseComObject on a RCW during
finalization would work in the current implementation of .NET, it isn't
something that is guaranteed to work in the future.

--
Keith

> -----Original Message-----
> From: Shawn A. Van Ness [mailto:savanness@xxxxxxxxx]
> Sent: Thursday, January 20, 2005 5:31 PM
> Subject: Re: should i treat COM Objects as IDisposeable things
>
> Shawn, IMHO you should consider taking Rich Blewett's advice, and lose
> the finalizer.
>
> Rationale: if your DisposableCom instance is unreachable, then so is
> the RCW (your '_comObject' field) -- both instances will be finalized
> at the same time, but in which order, who knows? -- and the RCW's
> finalizer will call Release() on your behalf.

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise