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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -