Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only properties should be deleted

I'm getting this error with JSLint: Only properties should be deleted

Why doesn't it like this? The variable I am attempting to delete is very large, so I was hoping to get a jump on the garbage collection. Is this not ok?

like image 479
Chris Dutrow Avatar asked Mar 16 '12 19:03

Chris Dutrow


2 Answers

delete is meant to delete properties on an object, not regular variables (properties on a VariableObject).

Instead, you could set all references to the value as null. JavaScript's GC will clean it up when it feels it needs to.

like image 91
alex Avatar answered Oct 03 '22 10:10

alex


if you just want to get rid of the jslint warning, you can try this:

var myHugeVariable = ...;

// do stuff with huge variable

delete window.myHugeVariable;

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

like image 45
jbabey Avatar answered Oct 03 '22 11:10

jbabey