PC Review


Reply
Thread Tools Rate Thread

Cleaning up COM objects

 
 
Frank Rizzo
Guest
Posts: n/a
 
      17th Jul 2006
I've seen code that in addition to calling
System.Runtime.InteropServices.Marshal.ReleaseComObject on all the
allocated COM objects also call GC.Collect. Do I need to do that, or is
it overkill? This is in a Console Application situation.

Example:

oXL.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject (oXL);
oXL = null;
GC.Collect(); //do I need this too?
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      17th Jul 2006
Frank,

The call to the static Collect method on the GC class is excessive. The
important thing is that you released the COM object. Calling Collect at
that point will just do a GC, which will clean up the wrappers, and any
other items in memory that are slated for GC.

Generally speaking, you shouldn't have to make the call to Collect if
you call ReleaseComObject correctly.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Frank Rizzo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I've seen code that in addition to calling
> System.Runtime.InteropServices.Marshal.ReleaseComObject on all the
> allocated COM objects also call GC.Collect. Do I need to do that, or is
> it overkill? This is in a Console Application situation.
>
> Example:
>
> oXL.Quit();
> System.Runtime.InteropServices.Marshal.ReleaseComObject (oXL);
> oXL = null;
> GC.Collect(); //do I need this too?



 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      18th Jul 2006
to add to paldino's contribution releasecomobject is necessary especially
for office interop

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Frank,
>
> The call to the static Collect method on the GC class is excessive.
> The important thing is that you released the COM object. Calling Collect
> at that point will just do a GC, which will clean up the wrappers, and any
> other items in memory that are slated for GC.
>
> Generally speaking, you shouldn't have to make the call to Collect if
> you call ReleaseComObject correctly.
>
> Hope this helps.
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Frank Rizzo" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I've seen code that in addition to calling
>> System.Runtime.InteropServices.Marshal.ReleaseComObject on all the
>> allocated COM objects also call GC.Collect. Do I need to do that, or is
>> it overkill? This is in a Console Application situation.
>>
>> Example:
>>
>> oXL.Quit();
>> System.Runtime.InteropServices.Marshal.ReleaseComObject (oXL);
>> oXL = null;
>> GC.Collect(); //do I need this too?

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cleaning a HP Laserjet 6P -- Which Cleaning Utility and Where? Brainstormer Printers 1 9th Jun 2010 07:54 AM
100% Free MS Access .NET Code Generator (tired of hand cranking business objects/data objects) ? MyGeneration Microsoft Access 0 27th Jan 2005 04:55 AM
Access is cleaning my objects =?Utf-8?B?TWF1cmljaW8gU2lsdmE=?= Microsoft Access Form Coding 0 29th Nov 2004 07:45 PM
When I delete objects VB.Net is not always cleaning up after itself Douglas Buchanan Microsoft Dot NET 0 29th Oct 2004 05:19 AM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian Microsoft Excel Programming 1 26th Aug 2004 10:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:22 PM.