js  内存泄露 运行一段时间,浏览器内存涨到1G+,然后就死掉了,怎么办,
网上讲了关于代码优化的东西,但是还是不懂自己的问题在哪里,求助啊
主要代码如下:
 function Start_ScanC(){
                if (statusC == 1 && WB2.checkLogin() == true) {
                    commentpage = 0;
                    //新一次的扫描重置页码
                    now_pointer = Find_Now(5);//查询指针
                    var w_info = Find_NowWeibo(now_pointer);
                    if (w_info != -1) {
                        var weiboid = w_info.rows[0].weiboid;
                        var weibocount = w_info.rows[0].comments_count;
                        now_pointer++;
                        Write_Now(now_pointer, 5);
                        if (weibocount > 0) {
                            WeiboComment(weiboid);
                        }
                        else {
                            Start_ScanC();
                        }
                    }
                    else 
                        if (w_info == -1) {
    Start_ScanU();
                        }
                }
                else {
                    Switch_APPKEYC();
                    
                }
            }function WeiboComment(weiboid){
                if (statusC == 1) {
                    WB2.anyWhere(function(W){
                        W.parseCMD("/comments/show.json", function(sResult, bStatus){
                            if (bStatus == true) {
                                var Comments;
                                if_scanC = sResult.next_cursor;
                                try {
                                    Comments = Comment_Json(sResult);//重新封装json 微博信息
                                } 
                                catch (e) {
                                    // alert("Comment_Json_Error:"+e)
                                }
                                if (Comments.length != 0) {
                                    total_comment += Comments.length;
                                    var count_comment = insertComment(Comments, weiboid);
                                    if (count_comment == -1) {//插入失败
                                        WeiboComment(weiboid);//继续执行
                                    }
                                    else {
                                        t_count_comment += count_comment;
                                        var total_comment = sResult.total_number - t_count_comment;
                                        document.getElementById("All_TogetherC").innerHTML = t_count_comment;
                                     
                                        the_num_scan_comment += Comments.length;
                                        document.getElementById("Num_TogetherC").innerHTML = the_num_scan_comment + "||" + count_comment + "||" + formatDate(new Date());
                                        if (if_scanC == 0 || sResult.comments.length == 0) {
                                            //重新扫描
                                            commentpage = 0;
                                            n_cid = 0;
                                            Start_ScanC();
                                        }
                                        else {
                                            WeiboComment(weiboid);
                                        }
                                    }

                                }
                                else 
                                    if (Comments.length == 0 && if_scanC != 0) {
                                        WeiboComment(weiboid);
                                        
                                    }
                                    else 
                                        if (Comments.length == 0 && if_scanC == 0) {
                                            commentpage = 0;
                                            n_cid = 0;
                                            Start_ScanC();
                                            
                                        }
                                
                            }
                            else {
                                statusC = 0;
                                ask_flagC--;
                                commentpage--;
                                Switch_APPKEY3(weiboid);
                            }
Comments = null;
                        }, {
                            count: 150,
                            id: weiboid,
                            max_id: n_cid,
                            page: ++commentpage
                        
                        }, {
                            method: 'get'
                        });
                    });
                }
               
            }javascript浏览器

解决方案 »

  1.   

    这看不出来
    内存泄露一般是,对DOM操作产生
    DOM添加自定义对象,把DOM挂到到其它对象,变量上,又循环操作
    --------------
    IE下你试试 用CollectGarbage()命令
      

  2.   

    内存泄露一般由未释放的全局变量引起,一些插件有内存泄露bug请理解全局变量的意义:
    除了定义在js全局的变量,所有全局对象的成员也都是全局变量,比如window['xxx']=xxx,这个也是全局变量,还有所有加载在页面的html及html对象的成员也都是全局变量插件使用不当可能引起内存泄露,又以图形插件内存泄露时增长最快,插件内部可能会注册一些全局变量保存结果,以方便实现一些功能,如果该变量的键值是随机值(为了避免重复),那么你不正常关闭插件,而直接清除视图(比如重新输入html,或移除其容器之类),则占据的内存不会被释放具体泄露位置你需要自己找,很简单的方法时逐步注释代码,知道内存不增长,先在大范围确定泄露位置,再在泄露部分(比如泄露位置是组件,逐步注释组件内部代码)重复以上过程,最终可以分析出泄漏原因