处置动态创建的控件 [英] Disposing dynamically created controls
问题描述
我有一个WinForms TabControl的,我动态添加的TabPages在运行时。每个TabPage的包含一个WebBrowser控件。我也有删除的TabPages在运行时的能力。
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.
我应该打扰的Dispose()荷兰国际集团的TabPage的和/或web浏览器控件?
Should I bother Dispose()ing the TabPage and/or WebBrowser controls?
在我看来,我至少应该的Dispose()WebBrowser控件,因为它是一个有点耗资源的。
It seems to me I should at least Dispose() the WebBrowser control since it is a bit of a resource hog.
推荐答案
您应该Dispose()方法的标签页时,将其删除。这将自动处理所有的子控件。
You should Dispose() your tab page when you remove it. This will automatically dispose all of the child controls.
有关详细信息,请参见 Control.Dispose 文档:
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.
这篇关于处置动态创建的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!