WinJS控件生命周期/事件侦听器和垃圾回收 [英] WinJS Control lifecycle / event listeners and garbage collection

查看:80
本文介绍了WinJS控件生命周期/事件侦听器和垃圾回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个案例,其中有一个自定义的WinJS控件,通过"data-win-control"使用。并由processAll()实例化。

I have currently a case where there's a custom WinJS control, used via "data-win-control" and instantiated by processAll().

要使此控件更新自身,它将在WinJS.Application上注册事件侦听器。现在我不确定这个控件是否仍然可以正确地进行垃圾收集,或者是否由于其事件监听器而被保存在内存中。

For this control to update itself, it will register event listeners on WinJS.Application. Now I'm not sure whether this control can still be properly garbage-collected or if it will be kept in memory due to its event listeners.

我想保持存在这些侦听器绑定到控件的生命周期,并且不希望在控件处理这些事件之前或控件已经很久消失之前注册它们。

I'd like to keep the existence of these listeners bound to the lifecycle of the control and don't want to register them before there's a control to handle these events or when the control has already long since disappeared.

推荐答案

嗨Marcus,

Hi Marcus,

查看Kraig图书的第131页(在论坛顶部)。

Check out page 131 of Kraig's book (at the top of the forum).

这应该可以帮助您了解何时在您的控件中以及何时不必担心removeEventListener。  (提示理解'闭包'数据结构)。

That should help you to understand when to worry about removeEventListener in your control and when you do not have to.  (hint understand the 'closure' data structure).

-Jeff


这篇关于WinJS控件生命周期/事件侦听器和垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆