none
What to use FinalReleaseComObject or ReleaseComObject in outlook appointment item disposing objects? RRS feed

  • Question

  • Outlook is not releasing the memory after closing an appointment/meeting time. What is advisable to use FinalReleaseComObject or ReleaseComObject? Any other best practice which you recommend to disposing the object in outlook appointment item.

    http://www.selvaonline.com - Live a Happy & Balanced Life



    • Edited by SelvaOnline Wednesday, May 21, 2014 8:16 PM
    Wednesday, May 21, 2014 8:15 PM

Answers

  • Hello Selva,

    The FinalReleaseComObject method sets the reference counter to 0, i.e. releases a COM object completely. The latter is used for decreasing the reference counter by 1. So, to finally release an object you need to call it multiple times. I'd recommend using the ReleaseCOMObject method because occasionally you may release objects that should be used later. Each time you call a property which returns an object you need to call the ReleaseCOMObject method after. It is simple as it can be.

    You need to release only objects you get from the Outlook object model via properties and methods. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the  Systematically Releasing Objects article in MSDN.  


    You may find a similar forum thread helpful.
    Wednesday, May 21, 2014 8:23 PM
  • Outlook just likes caching appointments, so even if you completely release it, Outlook will still cache in memory until another appointment is opened.

    What exactly are you trying to do? Why is this a problem?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, May 21, 2014 8:45 PM
  • Selva,

    > Also is there any impact to use FinalReleaseComObject  with respect to outlook performance?

    Nope. There is no need to use that method.

    You don't release all COM objects instantly, for example:

     if (Inspector.CurrentItem is MeetingItem)  

    The reference counter for the item shown in the inspector window is increased each time you call the CurrentItem property. I'd suggest storing an object reference and then cast it to the target type or release it. It looks like you need to review your code. 

    Note, other add-ins may not release COM objects properly and cause issues.

    Wednesday, May 21, 2014 9:38 PM

All replies

  • Hello Selva,

    The FinalReleaseComObject method sets the reference counter to 0, i.e. releases a COM object completely. The latter is used for decreasing the reference counter by 1. So, to finally release an object you need to call it multiple times. I'd recommend using the ReleaseCOMObject method because occasionally you may release objects that should be used later. Each time you call a property which returns an object you need to call the ReleaseCOMObject method after. It is simple as it can be.

    You need to release only objects you get from the Outlook object model via properties and methods. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the  Systematically Releasing Objects article in MSDN.  


    You may find a similar forum thread helpful.
    Wednesday, May 21, 2014 8:23 PM
  • Outlook just likes caching appointments, so even if you completely release it, Outlook will still cache in memory until another appointment is opened.

    What exactly are you trying to do? Why is this a problem?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, May 21, 2014 8:45 PM
  • Even after i close the both appointments still the memory is not completely released. For example, if i open 2 appointments, a 15k memory got increased to my outlook process but after i close those appointments, just half of the memory got released and still 7.5k memory keeps accumulating with outlook process. I have tried both FinalReleaseComObject and ReleaseComObject and FinalReleaseComObject seems to be releasing more memory but still it is not releasing completely.

    Question 1:
    Is there a way to release the maximum memory when we close the appointment or meeting item?

    Question 2 :
    Also is there any impact to use FinalReleaseComObject  with respect to outlook performance?

    Please find below my sample code.

    //Initialization
    if (Inspector.CurrentItem is MeetingItem) 
    {  
    MeetingItem MeetItem = Inspector.CurrentItem;  
    ApptItem = MeetItem.GetAssociatedAppointment(false); 

    //Implementation of the meeting item object

    //Releasing block

    if (ApptItem != null) 
    {
       Marshal.FinalReleaseComObject(ApptItem); 
    }

    ApptItem =null;

    GC.Collect()





    http://www.selvaonline.com - Live a Happy & Balanced Life



    • Edited by SelvaOnline Wednesday, May 21, 2014 9:14 PM
    Wednesday, May 21, 2014 9:06 PM
  • Selva,

    > Also is there any impact to use FinalReleaseComObject  with respect to outlook performance?

    Nope. There is no need to use that method.

    You don't release all COM objects instantly, for example:

     if (Inspector.CurrentItem is MeetingItem)  

    The reference counter for the item shown in the inspector window is increased each time you call the CurrentItem property. I'd suggest storing an object reference and then cast it to the target type or release it. It looks like you need to review your code. 

    Note, other add-ins may not release COM objects properly and cause issues.

    Wednesday, May 21, 2014 9:38 PM