Do not unsubscribe from COMObject events can cause memory leak although I use Marshal.FinalReleaseComObject?
I have defined new member in my class that is COMObject
protected COMObject.Call call_ = null;
This class has the following event handlers that I subscribed to
call_.ActionA += new COMObject.AEventHandler(AEvent);
call_.ActionB += new COMObject.BEventHandler(BEvent);
call_.Destructed += new COMObject.DestructedEventHandler(CallDestructedEvent);
When the Destructed event is called I do Marshal.FinalReleaseComObject
Marshal.FinalReleaseComObject(call_)
but not unsubscribe from the events
call_.ActionA -= new COMObject.AEventHandler(AEvent);
call_.ActionB -= new COMObject.BEventHandler(BEvent);
call_.Destructed -= new COMObject.DestructedEventHandler(CallDestructedEvent);
Is this can cause memory leak? or that the GC will handle it?
Can you link your answer to some MSDN or article?
Thanks! Dor.
Have you tried unsubscribing them before doing the release to see if it helps the memory leak?
You’ve got a destructed handler, you could do it in there.
Do you ever call any of the properties of the COM object, and if you do, have you released them properly too?
I think that even if you call FinalReleaseComObject on the parent object, if you haven’t released the child objects too then even though there are no reference to the parent there may still be references to the children hanging about.