performance - Javascript array deletion for garbage collection -
i have javascript array of objects each created 'new'. in event of error clear whole array gc'ed js engine. end sufficient set array variable 'null' or need splice elements array , set them null before setting array variable 'null'?
the reason asking in firefox displayed (console.log) array before assigning null , displayed object (which updated in display assume later) still shows elements of array when inspect later, hence doubt if elements being free'd or not.
tia
to clear array can set length zero:
var arr = [1,2,3,4,5]; console.log(arr); arr.length=0; console.log(arr);
result:
[1, 2, 3, 4, 5] []
edit: found on topic: http://davidwalsh.name/empty-array
looking @ comments seems setting variable new array simplest method:
arr = [];
according test results memory gc'd quicker setting length 0. imagine allocations triggering gc.
there interesting performance test on various methods here: http://jsperf.com/array-destroy
Comments
Post a Comment