Wednesday, December 1, 2010

Small Javascript question involving null and delete() in regards to garbage collection...

Programmer Question

Quite the title.



Anyhow, If I were to write something like:



var h = 5;  
delete h;


...I'd be eliminating the reference, but not the memory.

Now, if I set the variable to null, would that replace the memory with the null object?



var h = 5;  
h = null;


If so, wouldn't it be better to not only delete() the reference, but also replace the memory with a null object, for better memory optimization?



var h = 5;  
h = null;
delete h;


If I want to create a buckload of dynamic objects in a long and complex script, what's the best way to get rid of, or otherwise induce the garbage collector to eliminate, objects? Because in addition to just eliminating references, I had read that you could hint the collector to free memory if it was occupied by null...



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails