Windows Form Designer generated code

Disposing?

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).

You might also like...

Comments

About the author

Palo Mraz

Palo Mraz United States

I live in Slovakia with my wife, two sons (fulltime), one daughter (occasionally) and a dog. I've been doing Microsoft Windows development since 1988; primarily in VB. I'm a big fan of the MS .N...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov