kal*_*c29 6 javascript iframe internet-explorer memory-leaks
在我的公司,我们正在开发一个有多个iframe的SPA.有时一些帧不会加载到IE 11上,因为IE内存不足(内存中的iframe内容可能非常繁重,但Chrome和FF上的内容都没问题).
事实上,我们监控的事实是,每次重新加载页面时,使用的内存(从IE内存分析器或Windows任务管理器获取的数据)都会持续增加,直到达到1.6Gb阈值.
我发现这个非常有趣的帖子,我认为我所有的烦恼都会消失.由于我们没有使用jQuery,我将这个提供的片段改编为vanilla JS.我的想法是在页面重新加载之前清除帧以检查是否将回收使用的内存.
这是我写的代码:
window.addEventListener('beforeunload', function () {
[].slice.call(document.querySelectorAll('iframe')).forEach(function (frame) {
// remove all frame children
while (frame.contentWindow.document.body.firstChild) {
frame.contentWindow.document.body.removeChild(frame.contentWindow.document.body.firstChild);
}
frame.src = 'about:blank';
frame.parentNode.removeChild(frame);
});
// force garbarge collection for IE only
window.CollectGarbage && window.CollectGarbage();
});
Run Code Online (Sandbox Code Playgroud)
然后我打开IE的内存分析器并重新加载应用程序.然而,很少的内存被回收,我最终得到了这样的内存图
我错过了什么.有一些任何信息或建议吗?
谢谢.
| 归档时间: |
|
| 查看次数: |
3839 次 |
| 最近记录: |