Thread: Delete MailItem
View Single Post
  #6  
Old January 25th 07, 06:47 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Delete MailItem

You should always release all your objects and not just let them go out of
scope. I usually just set them to null and only call
Marshal.ReleaseComObject on objects declared at the module level and objects
being released on the close of the last Explorer, just before
OnDisconnection would fire. I then call in my teardown code to the
GC.Collect() method and wait for pending finalizers.

Some people call Marshal.ReleaseComObject every time they release an object,
but that's more performance intensive. If the code will run for a while
longer I don't do that usually.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"j" wrote in message
oups.com...
Thanx, great explanation.

Could u please suggest mr thr brst practise of releasing com objects in
.NET.
I develop addin for OL 2003 and using .net 2 C#. When and which objects
i should release ??

for example in newinspector event i get inspector object, after this i
perform casting to mailItem for example, and
let's say concernig to my business logic i should do nothing cause
this mailitem's named property is wrong or whatever, and i exit this
method (newinspector ) , my question is:

Do i need to release mailItem with Marshal.ReleaseComObject?? i guess
yes
and do i need to Release also inspector objec, that i get as parameter
in method?????

TNX in advance.


Ads