I have a WinForms TabControl that I am dynamically adding TabPages to at runtime. Each TabPage contains a WebBrowser control. I also have the ability to remove the TabPages at runtime.
Should I bother Dispose()ing the TabPage and/or WebBrowser controls?
It seems to me I should at least Dispose() the WebBrowser control since it is a bit of a resource hog.
You should Dispose() your tab page when you remove it. This will automatically dispose all of the child controls.
For details, see the Control.Dispose documentation:
Releases the unmanaged resources used by the Control and its child controls and optionally releases the managed resources.
The tab page's dispose will also dispose of all of the children controls for you.
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