用drip工具测试并解决ie window.open 带来的内存泄漏

来源:互联网 发布:网络舆情监测员职责 编辑:程序博客网 时间:2024/03/29 10:35
某一页面每打开一次,内存增长一次。达到一定程度后,页面假死,无法继续打开页面。
打开窗口代码如下。
function openEditor(){ 
var args=openEditor.arguments;
var MaxModalStyle = "status=1,scrollbars=1,width=" + (screen.width-15) + ",height=" + (screen.height-50) + ",left=0,top=10";
dgEditor=window.open("dd.jsp?kzh="+args[0]+"&nf=2009","",MaxModalStyle);           
return false;
}
考虑到和dgEditor对象没有释放代码有关系。代码修改为
var jdeditor = null;
function openEditor(){ 
var args=openEditor.arguments;
var MaxModalStyle = "status=1,scrollbars=1,width=" + (screen.width-15) + ",height=" + (screen.height-50) + ",left=0,top=10";
if(jdeditor!=null){
try{ 
jdeditor.close();
}catch(e2){
}
jdeditor = null;
}
jdeditor = window.open("dd.jsp?kzh="+args[0]","",MaxModalStyle);           
return false;
}
使用drip 工具检测, 内存增长大大减少。
起作用的是 jeditor.close(); 一句。
下图为drip 工具监测
注释掉 jeditor.close() 打开新窗口并关闭后内存陡增,使用jeditor.close() 后,再打开新窗口关闭,内存平稳。