none
Dictionary.Clear and AppointmentItem RRS feed

  • Question

  • I'm using a Dictionary to store a collection of AppointmentItem wrappers.

    Dictionary< string /*EntryID*/, AppointmentWrapperClass>AppointmentWrapper

    From time to time I need to clear the Dictionary

    MySelectionChangeHandler()

    {

        if( /*  some condititon * )

        {

              AppointmentWrapper.Remove( /*EntryID Goes here*/ );

         }

    }

    The AppointmentItems are removed, but I don't think the associated OUtlook.Appointment item is being released.  

    My guess is that the "Clear" member function doesn't call any of the classes methods to destroy the object (like a destructor, or Dispose, or something similar ).

    The object is of course removed from the Dictionary collection, but it's resources are not released.  Do I have to write code myself to release it before I invoke "Clear" or does "Clear" have a mechanism to call a class' destruction methods (e.g. dispose, destructors, etc.)

    Monday, June 23, 2014 7:07 PM

Answers

  • Hello German,

    No, the Clear method doesn't know anything about COM objects. You need to call the ReleaseComObject method before the Clear method or create your own dictionary class where in the Clear method you will call it.

    • Marked as answer by Germán_MSO Monday, June 23, 2014 7:34 PM
    Monday, June 23, 2014 7:18 PM

All replies

  • Hello German,

    No, the Clear method doesn't know anything about COM objects. You need to call the ReleaseComObject method before the Clear method or create your own dictionary class where in the Clear method you will call it.

    • Marked as answer by Germán_MSO Monday, June 23, 2014 7:34 PM
    Monday, June 23, 2014 7:18 PM
  • Thanks again!!!!

    Hopefully, my last question.

    For some reason when I have an appointment Item_BeforeDelete is called followed shortly by ItemRemove

    When I have an attendee (so now it's a meeting)  Item_BeforeDelete fires, but ItemRemove is not being called.

    I am clear that I've botched something here with keeping objects "alive". 

    Could you just give me a couple of hints as to where to look.

    Monday, June 23, 2014 7:38 PM
  • Hello German,

    It looks like you are talking about another issue, not related to the one described in the initial message. Moreover, I don't think that it is related to the way of releasing COM objects. Are you able to reproduce the issue with a newly created empty add-in project?

    FYI I'd recommend creating a new forum thread in such case. It will allow other forum readers recognize questions and answers easily.

    Wednesday, June 25, 2014 12:05 PM
  • As it turns out there's some issue with that particular installation of Outlook.

    The code runs fine on other machines, but the events don't fire as expected on the other.  I verified this using OutlookSpy.

    Thanks for your help.

    Monday, July 7, 2014 12:56 PM