I have been processing some client side data which may be up to 100MB in total. I have been using a global variable to store the data and the variable is declared at the top of my JS file:
var data = null;
Followed by the definition, there are some functions that load data to this variable, such as:
data = new Object();
data.array = [];
for (var i=0;i<10000;i++){
data.array[i] = i;
}
Then some operations will replace the data.array with some new data. I found that if I just set null to data before loading the new data, the memory of the browser will growing very fast:
data = null;
data = something_new;
data.array = something_new;
So I tried to use delete before loading new data:
delete data.array;
Now I have a question: do I have to delete each of the element in data.array or can I just delete the whole array using delete data.array; ?
Thanks!
deleteis a bad idea though. If you have new data available - just overwrite it. Ornullify otherwise.delete data;is valid and removesdatacompletely, Setting data to 'null' or 'undefined' still keeps a reference called 'data' referencingundefinedornullthus taking up a little space (whatever space a reference actualy uses?). If you don't intend on using data anymore delete it from the scope using delete.deletedoes not remove anything "from the scope". And, yes, you must be exceptionally precise when you're talking about the standards or abstract performance recommendations.