At this point it started to make sense, although I still wondered how are components without the New(IContainer)
constructor disposed of? I've found several such components in the System.Windows.Forms
namespace having only the default (parameterless) constructor, for example:
System.Windows.Forms.ColumnHeader
System.Windows.Forms.DataGridTableStyle
System.Windows.Forms.ColorDialog
System.Windows.Forms.FontDialog
System.Windows.Forms.OpenFileDialog
System.Windows.Forms.SaveFileDialog
...
Regarding their "dispose" behavior, the classes can be roughly divided into two groups:
The classes in the first group are always contained within a parent component (or control), so they are disposed along with their container. For instance System.Windows.Forms.ColumnHeader
instances are contained within the System.Windows.Forms.ListView.Columns
collection. The System.Windows.Forms.DataGridTableStyle
instances are contained within the System.Windows.Forms.DataGrid.TableStyles
collection.
The classes in the second group (represented by the System.Windows.Forms.*Dialog
classes above) are NOT disposed as part of their owning Form
disposal. I can only guess that the classes either don't hold onto any unmanaged resources during their lifetime, or there are some other mechanisms for releasing their resources (windows messages come to mind, for example).
Comments