我有一个关于添加/移除DOM对象监听器的问题。
我想问一下,当从页面中删除元素时,垃圾回收器能否收集内存。
例如:一个带有几个子项()的
例如:一个带有几个子项(
- 标签。
var ul = document.getElementById('someParent');
var children = ul.children;
var someFunction = function() {};
for(var i = 0; i < children.length; i++) {
children[i].addEventListener('click', someFunction);
}
// This is where I am not sure, would the garbage collector be able to collect
// the memory allocated on adding listener on children,
// if I remove the ul tag?
ul.remove();
children.length
不是一个好的条件。 - Luka