If I have an array like this:
var a = new Array(); a.push(1); a.push(2); a.push(3);
Which cleans up better, if there is a difference?
var len = a.length; a.splice(0,len);
OR
for (var i=0;i<a.length;i++) { a[i] = null; }
What do you mean by "clean up"?
If you're talking about memory management (e.g. something you'd have to worry about in C++ when using pointers and such), I don't think there's much that's in your hands when it comes to Javascript - it frees up memory on its own.
... Well, it's supposed to, anyway, sans memory leaks that developers haven't fixed. :p
I hate when I don't notice a new e-mail for the posts. You are correct that I meant memory management. You'd be surprised how some browsers that I'm not going to point at coughIEcough are horrible at memory clean up. For instance if you set an object to null that had member objects, those members are not cleaned up automatically.
I believe splice is slower to run initially, but better overall because it will leave the array empty instead of having 3 indexes equaling null.
Actually I probably wouldn't be surprised much at all - hence my little caveat at the bottom of my post. :p
I simply had never heard of such memory handling techniques in the scope of Javascript. A quick Google shows a variety of opinions/approaches (even one using the 'delete' operator such as you'd use in C++ to free up the memory of a pointer).
Yeah I know of delete but I've never used it. It seems too good to be true ha But I suppose I should run some benchmarks.