Good design, basically. The object model was well designed to ensure that the event source could not survive the subscriber. There is, of course, a circular link, the form saves the link to the control through its Controls collection, as well as a possible private variable, the control adds a link to the form through an event subscription. But the control lifetime is controlled by the form, both disappear when the user closes the window. This removes the usual single reference to the form object stored in the internal table, which maps the handle to the form. GC has no problems with circular links.
There are a few sharp edges, Application.Idle and SystemEvents events are the problem. They have a yellow ribbon in the MSDN library.
Utilization is also automatic, it is not used to unsubscribe from events in Winforms, each control provides links in its Controls collection. This starts with the Form class and automatically repeats through the tree. Overriding the form The Dispose () method is unusual, it also tends to cause a lot of anguish because this method is present in the form's Designer.cs file. Moving this method is fine, as the FormClosed event is used to place as an alternative.
It has a sharp edge with a chainsaw byte. Disposal of controls is not optional in Winforms. Very unusual, this is not necessary in everything else within the framework, and the finalizer refuses to forget to name it. Not in Winforms, if you use Controls.Clear or Remove, then the control that you remove is not deleted. It redraws into a hidden window called the "parking window." Keeping control to move the other parent. Good feature unless you move it elsewhere. He will live on this hidden window forever, a very nasty leak. Not a good design.
There are templates for solving the life time problem for events. The "weak event pattern" is rather arbitrary in .NET programming. This is a sign of the design problem bit signature, usually caused by sympathy for the observer pattern, because it works well in .NET, but does not like the contract that comes with it. An object-oriented model is almost always the root of the problem, for example, an abbreviation of three letters, the name of which should not be mentioned in the [winforms] tag :)
source share