2015-10-05 58 views

回答

3

我想你指的这个例子

// This is one way to remove all children from a node 
 
// box is an object reference to an element with children 
 

 
while (box.firstChild) { 
 
    //The list is LIVE so it will re-index each call 
 
    box.removeChild(box.firstChild); 
 
}

不,它不会导致内存泄漏。 第一个孩子被移除后会发生什么,第二个孩子将作为第一个孩子的位置,等等,直到没有更多的孩子离开。

垃圾收集通常不会按需求提供,虚拟机会在它认为可以的时候这样做,而浏览器之间的确会有所不同。