【发布时间】:2012-04-09 05:38:54
【问题描述】:
I've found that all of these scripts, while doing the same thing create memory leaks,问题是,为什么?
似乎是因为循环引用。
<script>
function runme() {
var node = document.createElement("div");
node.onclick = function() {
node.style.background = "red";
}
document.body.appendChild(node);
}
</script>
或
<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>
【问题讨论】:
-
到目前为止你发现了什么?
-
我发现他们都这样做了。但我不知道为什么。
标签: javascript internet-explorer memory-leaks