var Obj = function(){}; var X = new Obj();
will X = null properly clear memory?
Also would this be equivalent?
var Obj = function(){};
var X = {};
X.obj = new Obj();
delete(X.obj);
EDIT
It would seem that although deleting X.obj would NOT immediately clear memory, it would help the garbage collection. If I don’t delete X.obj, there would still be a pointer to an object and so the GC may not clean it up.
Although I’m picking @delnan’s answer, if you’re reading this you should def also catch Benubird’s article.
I also notice I accidentally wrote delete(X) originally instead of delete(X.obj) – sorry.
The short answer is that you don’t.
deletesimply removes a reference (and not in the way you try to use it, see the above link –deleteis one of those language features few people actually understand), nothing more. The implementation clears memory for you, but it’s not your business when (and even if, strictly speaking – this is why one shouldn’t rely on finalizers in GC’d languages that offer them) it does. Note though:On the plus side, that means you won’t get dangling pointer bugs or (save of course the aforementioned pitfalls) memory leaks.