项目内存泄漏问题及解决方案

    目前,mes项目存在内存泄漏问题.主要表现如下, 系统运行一段时间后,会越来越慢,严重的会导致ie崩溃.这点已经在零陵的实施项目充分体现出来了.
    我用工具测试的时侯发现,主要原因集中在窗口关闭后,用脚本创建的作为容器的dom元素因为含有tojsonstring属性而未能正常垃圾回收.

These are the names of the properties (or events) which still contained a not-null reference when the page was unloaded. These are possible candidates as the root-cause of the memory leak.

    证据如下;

image

   相关代码

Sail.apply = function(o, c, defaults){
    if(defaults){
        Sail.apply(o, defaults);
    }
    if(o && c && typeof c == 'object'){
        for(var p in c){
            o[p] = c[p];    //***
        }
    }
    return o;
};
createDiv : function(config){
            var div = document.createElement( "DIV" );    
            Sail.apply(div,config);
                        
            
            document.body.insertBefore(div); 
            return div;
},

   原型链污染

image

所以,相对应的解决方案有二:

1)在 ***处加一个判断,过滤掉tojsonstring,治标不治本的简单解决方法.

2)放弃原有的json格式化方法,直接用Ext的json格式方法.在sail_all文件中搜索有用到tojsonstring方法的地方,重写这部分代码.(推荐)

原文地址:https://www.cnblogs.com/ms_config/p/1847678.html