M
Max
I have the following code on a form that launches Microsoft Outlook and creates a new email message for the user:
where NAR(....) is defined as follows:
Problem is that when the Outlook application created is closed, it still resides
in memory. A quick check in the task list shows OUTLOOK.EXE wasting memory
space. If I run this code 10 times it will waste 180-250MB of memory. The only
way to kill it is by going to the system tray and manually removing it. How can
I force OUTLOOK.EXE to die? The Garbage collector does not seem to be doing a
good job. In fact the above code works and kills OUTLOOK.EXE when
is not presend and the Outlook application is not
shown, but when it is shown to the user then it just lies in memory even after it was closed.
Code:
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMail = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMail.HTMLBody = "SOME HTML TEXT HERE";
oMail.Display(oApp);
oMail.Close(Outlook.OlInspectorClose.olDiscard);
NAR(oMail);
oApp.Quit();
NAR(oApp);
GC.Collect();
GC.WaitForPendingFinalizers();
where NAR(....) is defined as follows:
Code:
private void NAR(object o)
{
try{ System.Runtime.InteropServices.Marshal.ReleaseComObject(o); }
catch{}
finally{ o = null; }
}
Problem is that when the Outlook application created is closed, it still resides
in memory. A quick check in the task list shows OUTLOOK.EXE wasting memory
space. If I run this code 10 times it will waste 180-250MB of memory. The only
way to kill it is by going to the system tray and manually removing it. How can
I force OUTLOOK.EXE to die? The Garbage collector does not seem to be doing a
good job. In fact the above code works and kills OUTLOOK.EXE when
Code:
oMail.Display(oApp);
shown, but when it is shown to the user then it just lies in memory even after it was closed.