Sunday, July 12, 2009

Creating Outlook Add-in! A fine line to walk

Have you ever created an Outlook add-ins and feel that it didn't work some time as expected ?

Read through to get the answers.....

The most common issue is so called "Memory Leak " and there is no obvious reason of why it happens.
To make the matter worse, there is no exception or visible effect in Outlook behaviour, its just some or the other property will not work.
Outlook object should to be respected and treated as pointers...
Though there is not 100% guarantee that it will never happen, but you can reduce the occurance to 90% .
Following thumb rules will always help it to reduce the "Memory Leak" to pittiance.

1. Com object which are initialized should be first relieved of by using System.Runtime.InteropServices.Marshal.FinalReleaseComObject
2. Don't forget to assign those component = nothing (in VB.NET)
3. Following code should also follow
GC.Collect()
GC.WaitForPendingFinalizers()

4. Also if you have added any eventhandler, it must be removed on the event once it is called.
eg. the following add handler
AddHandler CType(objContactItem, Microsoft.Office.Interop.Outlook.ContactItem).Write, AddressOf objContactItem_Write
should be removed when inspector close
RemoveHandler CType(objContactItem, Microsoft.Office.Interop.Outlook.ContactItem).Write, AddressOf objContactItem_Write

Following are the detailed article that must help you ....Search for all aritcle with tag OOM.
http://blogs.msdn.com/mstehle/archive/tags/OOM.NET/default.aspx

If you don't find the solution to the problem you can post me or at the following group.
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.outlook.program_addins

No comments: