Posts
415
Comments
233
Trackbacks
42
COM Interop Memory Leaks With Outlook 2007 VSTO Add-ins

Memory leaks can cause strange and unexpected behaviors in your applications.  Of course in this day of managed code we don’t see it as often as we used to and many of us are getting rusty in our skill to eliminate these problems.

Recently I ended up with a misbehaving Outlook 2007 add-in which resulted in time spent with Microsoft support.  The first thing that came out of that was a way to detect if an Outlook 2007 is experiencing memory leaks.  Below is a command line command that seems to report back which email items were involved in memory leaks if any occur.

Outlook /reportleakedrenitems

So how do you handle the problem?  Since the unmanged code in this case are COM interop object  you use Marshal.ReleaseComObject from the the System.Runtime.InteropServices namespaces.  Any place where you are explicitly creating an object out of the from the Microsoft.Office.Interop.Outlook namespace you need to explicitly release it using this method.  If all goes well this will exercise the ghost from your system.

Here are a couple of links related to the topic for further reading.

• ReleaseComObject - How it works
http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.marshal.releasecomobject.aspx

• OOM.NET: Part 1 - Introduction and Why Events Stop Firing...
http://blogs.msdn.com/mstehle/archive/2007/12/06/oom-net-part-1-introduction-why-events-stop-firing.aspx

• OOM.NET: Part 2 - Outlook Item Leaks
http://blogs.msdn.com/mstehle/archive/2007/12/07/oom-net-part-2-outlook-item-leaks.aspx

http://blogs.msdn.com/mstehle/archive/tags/OOM.NET/default.aspx

posted on Wednesday, October 26, 2011 9:38 AM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Comment *  
 

Tim Murphy

Tim is a Solutions Architect for PSC Group, LLC. He has been an IT consultant since 1999 specializing in Microsoft technologies. Along with running the Chicago Information Technology Architects Group and speaking on Microsoft and architecture topics he was also contributing author on "The Definitive Guide to the Microsoft Enterprise Library".



I review for the O'Reilly Blogger Review Program



Technorati Profile

www.flickr.com
Tag Cloud