最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript: remove all object elements of an associative array - Stack Overflow

programmeradmin3浏览0评论

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 bee 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!

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 bee 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!

Share Improve this question asked Jan 4, 2010 at 14:19 ErwinErwin 1,7723 gold badges24 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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

somearray.length = 0 should work.

发布评论

评论列表(0)

  1. 暂无评论