Here is a blog entry on why Microsoft didn't just implement RCWs the way you
are suggesting: http://blogs.msdn.com/cbrumme/archive/2003/04/16/51355.aspx

Antony
____________________

Antony Perkov
BitBolt Software Ltd
Web: www.bitbolt.com

-----Original Message-----
From: Matthew Wills [mailto:[EMAIL PROTECTED]
Sent: 13 April 2005 03:11
Subject: RCW generation with automatic ReleaseCOMObject

All,

We are automating Word / Excel from VB.NET and ran into the problem where
they won't shut down since the garbage collector hasn't garbage collected
the objects - so the reference counts of some of the COM objects is > 0.

We moved to using ReleaseCOMObject against all the objects, which obviously
got rid of the problem. (Note that I am aware that a commonly held view is
that the solution is to call GC.Collect until the problem goes away. For a
variety of reasons I disagree with this view - mainly since that technique
is not *guaranteed* to work. But lets put that to one side for now).

Nonetheless, the use of ReleaseCOMObject is quite fiddly, especially when
you have to clean up all the intermediate objects as well. As such, I am
seeing if there is an easier way. One concept that I *think* would work
would be to have all the classes in the RCW implement IDisposable, then in
C# / VB.NET 2005 I could use Using to manage the cleanup in a simpler way
(the code would still be longer than say the VB 6 equivalent, but would be
significantly shorter than currently). So my question is - is there any way
to generate a RCW where all the classes implement IDisposable and where
Dispose will automatically call ReleaseCOMObject?

Thanks
Matthew Wills @ MLC
Senior Analyst Programmer

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

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

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

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

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

Reply via email to