In my code I use an object and variables inside a function. When in that function I no longer use the object and variables I delete it:
delete myObject;
delete myVar;
Is it good practice?
Does it give speed?
My JavaScript is server-side on smart.joyent.com.
No. In fact it is disallowed in the new ECMAScript Fifth Edition ‘strict mode’:
If you really must, you can instead
=nullthe variable to free up any object it referenced for garbage collection, but it’s almost never going to result in any appreciable improvement in performance.Deleting properties of long-lived objects to free now-unused referenced objects can be a good idea, especially in the case of breaking DOM cycles to prevent memory leakage in IE. Deleting local variables inside a short-lived function isn’t sensible.