模拟qq闪图标,发现内存泄露非常严重,代码见内容

2 views
Skip to first unread message

lcl...@gmail.com

unread,
Mar 21, 2014, 5:44:40 AM3/21/14
to node-...@googlegroups.com, gyf.f...@gmail.com
function createTray(){
    this.icons = new Array('images/a1.png', 'images/a2.png');
    //this.icons = new Array('images/6.ico', 'images/7.ico');
    this.idx = 0;
    this.have_new_msg = false;
    this.tray = new gui.Tray({title:'System Tray',icon: this.icons[0]});
    this.chgicon = function(){
        if(arguments.length > 0){
            nstat = arguments[0];
            if (nstat == this.have_new_msg){
                return; //状态未改变,不处理
            }
            this.have_new_msg = nstat;
        }

        if(!this.have_new_msg){
            this.idx = 0;
            this.tray.icon = this.icons[0];
        }else{
            //this.icons[this.idx] = this.tray.icon;
            //alert(this.tray.icon);
            var c ='';
            for(var k in this.tray)
                c += k + "="+this.tray[k] + "\n";
            $('#sql').val(c);
            
            this.idx += 1; 
            this.idx = this.idx % this.icons.length;
            this.tray.icon = this.icons[this.idx]; //内存泄漏!!!!!!!!
            
            //if(this.tray){ this.tray.remove(); this.tray = null; }
            //this.tray = new gui.Tray({title:'System Tray',icon: this.icons[this.idx]});
        }
    }
};

function trayTimer()
{
    if(!mytray) return;
    mytray.chgicon();
    setTimeout(trayTimer, 700);
}


    mytray = new createTray();
    mytray.have_new_msg = true;
    trayTimer();

lcl...@gmail.com

unread,
Mar 21, 2014, 5:52:19 AM3/21/14
to node-...@googlegroups.com, gyf.f...@gmail.com, lcl...@gmail.com
版本信息:We are using node.js 0.9.2 v0.11.9

在 2014年3月21日星期五UTC+8下午5时44分40秒,lcl...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages