MozillaZine

destructor in JavaScript

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

Post Posted January 18th, 2009, 3:03 am

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

Post Posted January 18th, 2009, 6:57 am

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

Post Posted January 18th, 2009, 8:29 am

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

Return to Extension Development


Who is online

Users browsing this forum: sameera1991 and 3 guests