欢迎光临散文网 会员登陆 & 注册

ABB DSQC679 3HAC028357-001 关闭时从第一个视图调用其Dispose方法

2023-03-31 09:28 作者:文武双全何15859219118  | 我要投稿

学习并应用这些GUI控件内存管理的一般规则。

•具有图形表示的控件,例如ABB Numpad、TabControl、,

GroupBox、TpsLabel、ListView和Microsoft PicureBox以及

图中的DataGrid将自动添加到中的控件集合

初始化组件。它可能看起来是这样的:

this.Controls.Add(this.numPad1);

•如果上图代表应用程序的第一个视图,则控件

的基类处理

当应用程序关闭并且Dispose方法为

由TAF调用。当Dispose中的以下语句

方法被执行:base.Dispose(Dispose);

•但是,如果它代表应用程序的辅助视图(即

实际上是这种情况,从命令上的关闭按钮可以看出

bar),则必须在其关闭时从第一个视图调用其Dispose方法。

然后,它的基类将删除作为其控件一部分的所有控件

集合,就像前面的情况一样。

•GUI控件没有图形表示,但位于

表单下的组件窗格,例如GTPUSaveFileDialog,

RapidDataBindingSource、AlphaPad等未添加到

默认情况下控制集合。这些是你需要的

删除时要特别小心,因为垃圾收集器永远不会收集它们。

如果您忘记对此类控件显式调用Dispose,您将导致

永久性内存泄漏。仔细研究下一节中的代码示例

部分

Learn and apply these the general rules for memory management of GUI controls.

• Controls with a graphical representation, e.g the ABB Numpad, TabControl,

GroupBox, TpsLabel, ListView and the Microsoft PicureBox and

DataGrid in the figure, are automatically added to the controls collection in

InitializeComponent. It may look like this:

this.Controls.Add(this.numPad1);

• If the preceding figure represents the first view of your application, controls

with graphical representation will be disposed of by the base class of your

view class when your application is shut down and the Dispose method is

called by TAF. This happens when the following statement in your Dispose

method is executed: base.Dispose(disposing);

• If, however, it represents a secondary view of your application (which is

actually the case here, as you can tell from the close button on the command

bar), you must call its Dispose method from the first view when it is closed.

Its base class will then remove all controls that are part of its controls

collection, like in the previous case.

• GUI controls that have no graphical representation, but are located in the

Components pane under the form, for example GTPUSaveFileDialog,

RapidDataBindingSource, AlphaPad and so on are NOT added to the

controls collection by default. These are the ones that you need to be

especially careful to remove, as no garbage collector will ever gather them.

If you forget to explicitly call Dispose on such controls you will have caused

a permanent memory leak. Carefully study the code example in the next

section.


ABB DSQC679 3HAC028357-001 关闭时从第一个视图调用其Dispose方法的评论 (共 条)

分享到微博请遵守国家法律