Best way to deallocate an array of array in javascript

后端 未结 3 1656
北恋
北恋 2020-12-18 05:26

What is the best way to deallocate an array of array in javascript to make sure no memory leaks will happen?

var foo = new Array();
foo[0] = new Array();
foo         


        
3条回答
  •  自闭症患者
    2020-12-18 06:18

    foo = null;
    

    should be enough for the garbage collector to get rid of the array, including all its child arrays (assuming nothing else has a reference to them). Note that it will only get rid of it when it wants to, not immediately, so don't be surprised if the browser's memory consumption doesn't drop straight away: that isn't a leak.

    It potentially gets more complicated if any of those array elements contain references to DOM nodes.

提交回复
热议问题