Releasing COM Components

  • Thread starter Thread starter Nenad Dobrilovic
  • Start date Start date
N

Nenad Dobrilovic

I have created programmatically a structure of root MAPIFolder, with
subfolders and MailItems.

Is it necessary to explicitly release all items (subfolders and mail items)
or I can release only the root MAPIFolder?
 
Best practice is to always release everything.

Since you provide no information about your development language or platform
or even the Outlook versions you're targeting it's impossible to say more.
 
In that case in addition to setting all COM objects to null in the
procedures where you declare them you should also use
Marshal.ReleaseComObject() on them if you no longer need the objects or any
other related objects.

For example, if you have a locally declared Inspector object don't use
Marshal.ReleaseComObject() on it if you still need other instances of that
object anywhere in your code. Otherwise you get an RCW error when you try to
refer to the Inspector in other parts of your code.
 
Back
Top