Let's say I have some component like this:
class SomeForm : Form
{
private Control example;
public void Stuff()
{
this.example = new ComboBox();
// ...
this.Controls.Add(example);
}
public void OtherStuff()
{
this.Controls.Remove(example);
}
}
Who is responsible for calling Dispose
on the example control? Does removing it from this.Controls
cause it to be disposed? Or does this leak bunches of window handles backing the controls?
(For reference, I'm asking this because I don't see where the Windows Forms Designer generates code to call Dispose on a Form's children)
Form.Dispose()
will dispose of the controls within the Controls
collection. So removing the control from Controls
will require you to dispose of the control yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With