【发布时间】:2018-06-28 03:11:47
【问题描述】:
我有以下 HTML 可以重现我看到的问题。随着我随着时间的推移添加/删除 IFrame,浏览器永远不会释放 IFrame 内存。结果,内存会随着时间的推移而增长和增长,从而导致性能下降。我已经在 Safari/IE11/Edge 上看到了这种影响,而 Firefox/Chrome 处理得更好。有人对如何规避 IFrame 内存泄漏有任何提示吗?
<html>
<body>
<button onclick="add()">ADD</button>
<button onclick="remove()">REMOVE</button>
<script>
function add() {
var ifrm = document.createElement('iframe');
ifrm.setAttribute('id', 'ifrm');
ifrm.setAttribute('src', 'http://somewebsite.com');
document.body.appendChild(ifrm);
}
function remove() {
document.body.removeChild(document.getElementById('ifrm'));
}
</script>
</body>
</html>
【问题讨论】:
-
我遇到了同样的问题。尝试更改为打开 IE11 的新窗口。
标签: javascript iframe memory-leaks safari internet-explorer-11