iwek
iwek

Reputation: 1608

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?

Upvotes: 1

Views: 1807

Answers (1)

user166390
user166390

Reputation:

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.

Upvotes: 1

Related Questions