[英]Javascript (Dojo): Is event-listener removed when object is destroyed
I create a dialog in which there are some buttons with events. 我创建一个对话框,其中有一些带有事件的按钮。 When I destroy the dialog recursive programmatical or by pressing the X are there deleted all the created event-listener (hide, cancel, click1, click2)? 当我以编程方式销毁对话框或按X时,是否删除了所有已创建的事件侦听器(隐藏,取消,click1,click2)?
Because I call this part (here I posted only a simplified version of my code) very often (for different dialogs) and it seems that my code could have some memory leaks I want to eliminate them. 因为我经常(对于不同的对话框)称呼这一部分(在这里我只发布了代码的简化版本),并且看来我的代码可能存在一些内存泄漏,所以我想消除它们。 So please tell me, is it necassary/make sense to remove the event-listener all by myself like eventHide.remove(); 因此,请告诉我,像eventHide.remove();一样自行删除事件侦听器是否必要/有意义? ? ?
Additional: I tried to use the on (like the eventHide) for the click- and cancel-events but it didn't work. 另外:我尝试将on(如eventHide)用于单击和取消事件,但是没有用。
var myDialog = new Dialog({
content: 'Testdialog'
});
myDialog.show();
var btn1 = new dijit.form.Button({ label: "Ok" });
var btn2 = new dijit.form.Button({ label: "Help" });
myDialog.containerNode.appendChild(btn1.domNode);
myDialog.containerNode.appendChild(btn2.domNode);
var eventHide = on.once(myDialog, "hide", function(e){
console.log('hide');
myDialog.destroyRecursive();
});
dojo.connect(btn1, "onClick", function(){
console.log('click ok');
myDialog.destroyRecursive();
});
dojo.connect(btn2, "onClick", function(){
console.log('click help');
myDialog.destroyRecursive();
});
dojo.connect(myDialog, "onCancel", function(){
console.log('cancel');
});
You could use this.own
defined in dijit/Destroyable, which is a base of dijit/_WidgetBase and thus most widgets (make sure your custom widget inherit from hit.). 您可以使用dijit / Destroyable中定义的this.own
,它是dijit / _WidgetBase的基础,因此也是大多数小部件的基础(确保自定义小部件继承自hit。)。
dijit/Destroyable is used to track handles of an instance, and then destroy them when the instance is destroyed. dijit / Destroyable用于跟踪实例的句柄,然后在销毁实例时销毁它们。
More infos: http://dojotoolkit.org/reference-guide/1.10/dijit/Destroyable.html 更多信息: http : //dojotoolkit.org/reference-guide/1.10/dijit/Destroyable.html
http://dojotoolkit.org/reference-guide/1.8/dojo/Evented.html http://dojotoolkit.org/reference-guide/1.8/dojo/Evented.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.