2015-10-05 63 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); 
 
}

不,它不會導致內存泄漏。 第一個孩子被移除後會發生什麼,第二個孩子將作爲第一個孩子的位置,等等,直到沒有更多的孩子離開。

垃圾收集通常不會按需求提供,虛擬機會在它認爲可以的時候這樣做,而瀏覽器之間的確會有所不同。