Javascript Destroy Object

I

Ian Renfrew

Does Javascript supply a function that destroys an object? If so, is there a
dependancy on Javascript version?

Thanks in advance, Ian Renfrew
 
L

Lasse Reichstein Nielsen

Ian Renfrew said:
Does Javascript supply a function that destroys an object?

No. There is no such operator or function in ECMAScript, nor in any of
the implementations that I have heard of.

Destroying an object is generally a bad idea, since it would leave
variables with references to that object dangling ... or require that
they are all found and changed.
If so, is there a dependancy on Javascript version?

No :)

/L
 
G

Grant Wagner

Danny said:
The way I've removed an object to it nulls out, just like using cp obj
/dev/null, send to null, in js, assign to null, obj=null; .

Danny

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top