Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: remove all object elements of an associative array

I would like to know the most efficient way of emptying an associative array without causing any memory leak (the values are js objects)

Just to be sure, I have tried iterating through the elements of the array, calling 'delete' operation for each element object, so that all of the element objects will become candidates for garbage collection. Finally, I reset the assoc array using: somearray = {};

Is it necessary to call the 'delete' operation for each of the element? Or does resetting the variable value suffice so that all elements will be garbage collected?

Thanks!

like image 492
Erwin Avatar asked Jan 04 '10 14:01

Erwin


1 Answers

As long as neither your objects nor the associative array are referenced anywhere else, resetting the array should do it.

Calling delete on each object is only necessary in IE6 on a DOM element. See here

like image 161
SLaks Avatar answered Oct 15 '22 14:10

SLaks