开发者

Javascript - how do I stop / delete / remove / kill a new object class instantiation?

sorry for the crappy description but there is some class:

Event.Ticker = Class.create();

Object.extend(Event.Tick.prototype, { initialize: function (container, seconds) {

...etc..

开发者_如何学编程

AND this code:

new Event.Ticker("ID", 20);

so counter runs down from 20 to 0 how do I kill this at any point?


Presumably there is a way to invoke

myEvent.Stop()

which would presumably call clearInterval or whatnot, but it depends upon said interface exposed.

JavaScript is fully garbage-collected and there is no implicit (or explicit) destructors. All "cleanup" (such as Stop), if required, must be done explicitly.

There is no way to "delete" an object, only to let it become unreachable in which case the GC may reclaim ("destroy") it if it feels like it -- however both setInterval and setTimeout will maintain a strong reference to the callback which 1) will fire the callback even if the callback and/or myEvent is not strongly reachable elsewhere 2) may prevent other objects from being eligible for reclamation if they are reachable via the callback.

Happy coding.


See Garbage Collection: Reachability of an Object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜