I created a simple Outlook 2007 add-in using C #, which iterates over a list of messages and analyzes their attachments.
I use this add-in to set out ~ 25,000 selected posts. Immediately, however, I notice the use of Outlook memory (visible through perfmon) firing. After starting the add-in in debug mode, it is obvious that the memory is assigned to Outlook in the first instance of access to the Message Attachments collection. This memory never returns to the system; Outlook continues to consume memory up to 1 GB (after about 12,000 messages), after which I get an error "from memory or system resources." Any ideas?
Here is the piece of code:
for(int i = 1; i <= objSelectedItems.Count; i++)
{
Object objMsg = objSelectedItems[i];
if (objMsg is Outlook.MailItem)
{
Outlook.MailItem Msg = objMsg as Outlook.MailItem;
Outlook.Attachments objAttachments = Msg.Attachments;
Msg.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
Marshal.ReleaseComObject(objAttachments);
Marshal.ReleaseComObject(Msg);
}
Marshal.ReleaseComObject(objMsg);
GC.Collect();
GC.WaitForPendingFinalizers();
}
Nickl