destructor in JavaScript

Talk about add-ons and extension development.
Post Reply
pelle2004
Posts: 9
Joined: October 18th, 2008, 11:22 am

destructor in JavaScript

Post by pelle2004 »

How can you tell that a JavaScript's Object has been destructed.
Is there a dtor function in JS?
Is the garbage collection working well in JS ?
Crazy-EyE
Posts: 397
Joined: February 24th, 2008, 6:27 am
Location: Moscow, Russia

Re: destructor in JavaScript

Post by Crazy-EyE »

AFAIK there is no such a function. Garbage collection works well so you don't normally need any destructor.

But if you really need the destructor (for example, you want logging construction/destruction) you can probably use link to the instance of binary (C++) XPCOM-component. If it's the only link to this instance, when JS object will be GCed, component will be freed and its destructor will be called. Then you'll probably need some JS callback function to be called from this binary destructor so be afraid of cycles which may be not GCed. Is there any already existing debug API for this??? What about Venkman?

Also there are Leak Tools that may be more helpful for you.
pelle2004
Posts: 9
Joined: October 18th, 2008, 11:22 am

Re: destructor in JavaScript

Post by pelle2004 »

I added the 'Leak Monitor' and found some observers leaking.

I only needed to be sure that I didn't have any thing left.

/Thanks
Post Reply