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


Guest


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: 18810
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 http://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/


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