I have a third party ActiveX control that I am embedding in a form. The control’s class implements IDisposable. My question is should I manually call the control’s dispose method either in the form closing event or go into the designer and edit the form dispose method to call the control’s dispose.
I understand that a form calls the dispose methods of all the controls it owns, however are there any exceptions since this is a COM control. Thanks.
PS: I am using Visual Studio 2008, .Net 3.5, Project Type: Windows Forms Application
No, there is nothing special you have to do.
Because the
Controlclass (from which other container controls such asForminherit from) implements theIDisposableinterface, it should (if it follows the standardIDisposableimplementation guidelines) dispose of any references that it holds that implement theIDisposableinterface.That said, your control, assuming that it is in the controls collection exposed by the
Controlsproperty, will have it’sIDisposable.Disposemethod called when the window containing it is closed (as closing the window causes the window’sDisposemethod to be called).