A question to clarify the "Release Com Objects yourself" thing...

Add-in Express™ Support Service
That's what is more important than anything else

A question to clarify the "Release Com Objects yourself" thing...
 
Mike Medved




Posts: 41
Joined: 2010-10-19
Does that mean that I cannot have code like this:


for (int i=1;i<Fold.Folders.Count;i++)

or even

cnt=Fold.Folders.Count;

because I am creating COM objects while doing that and since I don't have vars that point to them I cannot release them?
Posted 20 Oct, 2010 15:23:46 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hi Mike,

Exactly.Instead you need to have a variable containing Fold.Folders. Say:

Outlook.Folders folders = Fold.Folders;
for (int i=1;i<Fold.Folders.Count;i++) 
{
   //
}
Marshal.ReleaseComObject(folders)


When using COM objects, the Release stage in the Get-Use-Release sequence should be coded explicitely. Other interesting restrictions are described in When to release COM objects in a managed COM add-in?

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2010 02:14:28 Top