Only properties need to be deleted

I get this error with JSLint: Only properties should be removed

Why is this not so? The variable that I am trying to delete is very large, so I was hoping to get a jump in garbage collection. This not normal?

+7
source share
3 answers

delete intended to delete object properties, not regular variables (properties in VariableObject).

Instead, you can set all references to a value as null . JavaScript GC will clean it when it feels what it needs.

+11
source

If you just want to get rid of the jslint warning, you can try the following:

 var myHugeVariable = ...; // do stuff with huge variable delete window.myHugeVariable; 

This should work, since all global variables are actually properties of the global object.

+2
source

As a rule, there is no need to release variables. The javascript engine does this automatically.

Or you can let the variable equal undefined, so you can pass the jslint check.

 var a=11; a = undefined; 

Not recommended.

+1
source

All Articles