A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Release COM components



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 3rd 08, 02:48 PM posted to microsoft.public.outlook.program_addins
Nenad Dobrilovic
external usenet poster
 
Posts: 10
Default Release COM components

Is it really necessary to release COM components from Office PIA, when you
don't need them anymore by invoking Marshal.ReleaseComObject(..)?

I found various and contradictory advices on this topic on the web. In my
opinion, since Office PIA is always returning a new references to its
interfaces as returning values from its methods, it is not necessary to
explicitly release it. Am I right?
--
Nenad Dobrilovic
Ads
  #2  
Old October 3rd 08, 03:40 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Release COM components

No, that's not correct. In many cases unless you do use
Marshal.ReleaseComObject() you don't know when the objects are actually
released, you can get memory leaks and in the case of Word objects for
WordMail you can get kernel32 errors.

You do have to be careful as to when you call Marshal.ReleaseComObject()
because it releases all references to an object, even copies or different
instances of the object. For example call Marshal.ReleaseComObject() on an
Inspector passed to a class or method and not only that copy but the
original object are released and attempts to use the object result in an
invalid RCW error.

Only call Marshal.ReleaseComObject() when you are completely finished with
an object and any copies/instances of the object.

Another reason to call Marshal.ReleaseComObject() is the default 256 RPC
channel limit to Exchange. If you end up with that many or more current
objects instantiated, for example in a loop, then you will get errors back
when trying to instantiate any additional objects. That applies even to
implicit objects internally instantiated due to dot operators. Setting the
instances to null often isn't enough to release RPC channels due to the
indeterminate nature of when the GC runs. In those cases often the only way
to complete a loop is to explicitly call to Marshal.ReleaseComObject() and
then to GC.Collect().

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad Dobrilovic" wrote in
message ...
Is it really necessary to release COM components from Office PIA, when you
don't need them anymore by invoking Marshal.ReleaseComObject(..)?

I found various and contradictory advices on this topic on the web. In my
opinion, since Office PIA is always returning a new references to its
interfaces as returning values from its methods, it is not necessary to
explicitly release it. Am I right?
--
Nenad Dobrilovic


  #3  
Old October 3rd 08, 03:53 PM posted to microsoft.public.outlook.program_addins
Nenad Dobrilovic
external usenet poster
 
Posts: 10
Default Release COM components

Thanks a lot. Does it mean that implementing a Dispose pattern for a wrapper
classes (InspectorWrapper, ExplorerWrapper, etc) is a good idea?
--
Nenad Dobrilovic


"Ken Slovak - [MVP - Outlook]" wrote:

No, that's not correct. In many cases unless you do use
Marshal.ReleaseComObject() you don't know when the objects are actually
released, you can get memory leaks and in the case of Word objects for
WordMail you can get kernel32 errors.

You do have to be careful as to when you call Marshal.ReleaseComObject()
because it releases all references to an object, even copies or different
instances of the object. For example call Marshal.ReleaseComObject() on an
Inspector passed to a class or method and not only that copy but the
original object are released and attempts to use the object result in an
invalid RCW error.

Only call Marshal.ReleaseComObject() when you are completely finished with
an object and any copies/instances of the object.

Another reason to call Marshal.ReleaseComObject() is the default 256 RPC
channel limit to Exchange. If you end up with that many or more current
objects instantiated, for example in a loop, then you will get errors back
when trying to instantiate any additional objects. That applies even to
implicit objects internally instantiated due to dot operators. Setting the
instances to null often isn't enough to release RPC channels due to the
indeterminate nature of when the GC runs. In those cases often the only way
to complete a loop is to explicitly call to Marshal.ReleaseComObject() and
then to GC.Collect().

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad Dobrilovic" wrote in
message ...
Is it really necessary to release COM components from Office PIA, when you
don't need them anymore by invoking Marshal.ReleaseComObject(..)?

I found various and contradictory advices on this topic on the web. In my
opinion, since Office PIA is always returning a new references to its
interfaces as returning values from its methods, it is not necessary to
explicitly release it. Am I right?
--
Nenad Dobrilovic



  #4  
Old October 3rd 08, 06:47 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Release COM components

I prefer not to use Dispose unless something calls it directly. In my
experiments with Dispose I've seen it not fire until after Outlook
disappeared from the UI, so you never know when it will be called. I prefer
to control things myself so I usually implement a "kill' method that I call.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad Dobrilovic" wrote in
message ...
Thanks a lot. Does it mean that implementing a Dispose pattern for a
wrapper
classes (InspectorWrapper, ExplorerWrapper, etc) is a good idea?
--
Nenad Dobrilovic


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Identifying components of email message ed Outlook and VBA 4 May 15th 07 05:41 PM
Customizing the compose form in OL2007(release). lee Outlook - Using Forms 1 January 11th 07 04:47 PM
Revert to prior release after upgrade of OE SWF Outlook Express 8 September 14th 06 10:48 PM
PST files and other components Mark Outlook - Installation 4 April 1st 06 04:54 AM
Release TS Mathews Outlook - General Queries 1 March 6th 06 02:08 PM


All times are GMT +1. The time now is 09:23 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.