我正在通过编程从DOM中删除HTMLInputElement。然后我运行堆转储,这些HTMLInputElements不在堆转储中。
但是,当我输入HTMLInputElement时,HTMLInputElement不会被垃圾回收,我可以在堆转储(在构造函数中)中看到它。
如果有附加到这些元素的处理程序,相关对象也不会从内存中丢弃。
在Chrome 75中观察到。
似乎IE11没有遇到这个问题。
<html>
<body>
<button id="button">Add</button>
<div id="container"></div>
<script>
var button = document.getElementById("button");
var cont = document.getElementById("container");
button.addEventListener("click", function() {
if (cont.childNodes.length > 0) {
cont.removeChild(cont.childNodes[0]);
}
var input = document.createElement("input");
input.type = "text";
cont.appendChild(input)
})
</script>
</body>
</html>我希望这些元素会被丢弃。
发布于 2019-07-26 05:06:06
我也一样- 75.0.3770.142 (64位)版本。
然而,随机选择的32位铬的旧版本- 69.0.3450.0 -似乎没有这个问题。
构建在这里:https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win/564085/
https://stackoverflow.com/questions/57205068
复制相似问题