JS内存管理测试

打开调试器,切换到timer,点击左下角的record按钮开始,切换到memory视图,在文档中点击鼠标左右键,看股价走势图
function Allocate(kbs){
    this.mem = new Array(kbs * 1024 + 1).join(' ');
    this.destroy = function(){
        this.mem = null;
    }
}
var located = [];
window.onload = function(){
    document.body.oncontextmenu = function(){
        if(!located.length){
            return false;
        }
        located[0].destroy();
        located[0] = null;
        
        located = located.slice(1);
        return false;
    }
    document.body.onclick = function(evt){
        evt = evt || window.event;
        if(evt.button != 0){
            return false
        }
        located.push(new Allocate(1024));
    }
    // setInterval(function(){  //如果有这个Interval的话内存居高不下
    //     located;
    // }, 1000);
}

 

posted @ 2013-07-24 23:24  Arliang  阅读(291)  评论(0编辑  收藏  举报