My questions is regarding VSTO .NET development with Outlook.
Due to the way .NET event handlers are handled in VSTO, it is necessary to hold a reference to the COM object representing the item for the event handler on the item to be fired. This is done by declaring a class level variable that will keep the reference from being garbage collected.
My addin is handling the BeforeDelete event for the Calender, Contacts, and Tasks.
I am worried that keeping List's of references to all individual items is going to use a lot of Memory for users with large collections of Appointment items, Contacts, and Tasks.
My questions is about the underlying COM object I am keeping a reference to. Does this object hold all of the item's details, or is it just a pointer that Outlook uses to load the details from the datastore. For example, when I access the FirstName property of a Contact item, is this loaded directly from memory or is is loaded from Outlooks PST file.
I don't recommend holding references to every calendar item, task and contact. This will cause the majority of RCW's to make it to gen 1 or gen 2, meaning they are not likely to ever get cleaned up by a garbage collection. The objects themselves never move into the .net space, but you will get a RCW for each one, which stops the memory from being cleaned up on the unmanaged side. This also can cause issues in Outlook where calendar items get locked and you can't resize them, and other random issues...
I would recommend instead using my FolderMonitor class out of my VSTO Contrib project (http://vstocontrib.codeplex.com/SourceControl/changeset/view/50a83624e34d#src%2fVSTOContrib.Outlook%2fOutlookFolderMonitor.cs) which will raise a deleted event when an item is being deleted, that way you will only have a reference to 3 RCW's (Contact Folder, Tasks Folder and Calendar folder).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With