PDA

View Full Version : Destroying javascript object



72
28 Apr 2007, 10:05 AM
If i close contentPanel tab with close icon, is content panel destroyed (memory released) and what about any content under it? Is destroyed too?

72
28 Apr 2007, 11:46 AM
The question was if javascript can release memory, but after that i found this


Setting an object reference null does not "null the object out" or "copy
the object to /dev/null"... it sets that object reference to null. If
that reference were the last reference to the object, the object is
eligible for garbage collection. If that reference were not the last
reference to the object, then the object is still reachable and will not
be garbage collected.

var objectToBeDestroyed = new Object();
var anotherReference = objectToBeDestroyed;
objectToBeDestroyed = null

-objectToBeDestroyed- is not being "copied to /dev/null" because it is
still reachable.

Even adding:

anotherReference = null;

will not "null out the object", it simply makes the object unreachable
and eligible for garbage collection. There is no guarantee that it will
be garbage collected. In fact, in a short-lived script, the garbage
collector may not run at all during the execution of the script although
it's almost certain to run when the page is torn down (you close the
browser or navigate away from the page).
source: http://www.thescripts.com/forum/thread152552.html


It means that no object is really released from Browsers memory, objects still exists and im aware of garbage. I have dynamicaly loaded tabs and after close i want to destroy object (release memory). But i dont need content panels still in memory but seems as only one solution (in that case)

Nullity
28 Apr 2007, 7:16 PM
No, clicking the close button does not remove the dialog from memory. To accomplish that, you would have to do something like:


// where el = content panel/dialog/tab/whatever
el.on('hide', el.destroy);


Read up on event listeners and the 'destroy' function in the docs.

72
28 Apr 2007, 11:42 PM
Yep, that was first i tried (destroy() method) but it not remove panel from memory (object still exists) and depend on what i read i can say it is impossible in JavaScript