![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |