Javascript IE6中的循环引用导致内存泄漏

Javascript IE6中的循环引用导致内存泄漏,javascript,internet-explorer,memory-leaks,Javascript,Internet Explorer,Memory Leaks,问题是,为什么 这似乎是因为循环引用 <script> function runme() { var node = document.createElement("div"); node.onclick = function() { node.style.background = "red"; } document.body.appendChild(node); } </script> 函数runme(){ var节点=document.cre

问题是,为什么

这似乎是因为循环引用

<script>
function runme() {
  var node = document.createElement("div");
  node.onclick = function() {
    node.style.background = "red";
  }
  document.body.appendChild(node);
}
</script>

函数runme(){
var节点=document.createElement(“div”);
node.onclick=function(){
node.style.background=“红色”;
}
document.body.appendChild(节点);
}


函数runme(){
var节点=document.createElement(“div”);
node.onclick=function(){}
document.body.appendChild(节点);
}


var节点=document.createElement(“div”);
document.body.appendChild(节点);
函数runme(){
node.onclick=function(){}
}


var节点=document.createElement(“div”);
node.onclick=空;
document.body.appendChild(节点);
函数为空(){
}

我不知道如何检测泄漏,但对我来说,只有前两个示例会产生泄漏。(使用检测)

原因:在runme()中,您为节点创建了一个闭包

当您在所有4个示例中都出现泄漏时,您应该展示如何删除节点(这就是泄漏发生的时间点)


但是:解决方案是在删除元素之前删除事件:

到目前为止,您发现了什么?我发现它们都有发现。但我不知道为什么。
<script>
function runme() {
  var node = document.createElement("div");
  node.onclick = function() {}
  document.body.appendChild(node);
}
</script>
<script>
var node = document.createElement("div");
document.body.appendChild(node);
function runme() {
  node.onclick = function() {}
}
</script>
<script>
var node = document.createElement("div");
node.onclick = empty;
document.body.appendChild(node);
function empty() {
}
</script>