2012-07-09 35 views
3

使用Raphael庫餅圖和hover屬性會發生嚴重內存泄漏。如果我刪除包含懸停屬性的代碼,它的效果很好,當我將它添加回內存佔用區域時,它會穩定增長,並且懸停在餅圖上會更加增加內存佔用量。與大多數其他示例不同,我使用window.setInterval來不斷更新頁面(如果這有幫助的話)。 我不知道如何解決這個問題,並尋求幫助。使用raphael.js進行內存泄漏

以下是我正在做的事情的基礎知識......幾乎在Raphael網站上使用動態pieChart並添加了間隔計時器。我不知道如何利用沒有內存問題的懸停效果???:

window.onload = setInterval(drawThePie, 10000); 
function drawThePie() { 
    var mainCont = parent.frames["main"].document; 
    mainCont.getElementById("holder").innerHTML = "Getting data.."; 

    //..Setting values for pieChart and legend into arrays here 

    //..Looping through color array and setting values for colorlist below 

      var r = Raphael("holder"); 
    var aCircle = r.aCircle(85,85,78).attr({fill: "black"}); 

      pie = r.piechart(85,85,75,data, {"legend": legend, "legendpos": "east", colors: colorlist }); 
    if(dataNotZero > 0) { mainCont.getElementById("holder").innerHTML = "";} 

      pie.hover(function() { 
       this.sector.stop(); 
       this.sector.scale(1.1, 1.1, this.cx, this.cy); 

       if (this.label) { 
        this.label[0].stop(); 
        this.label[0].attr({ r: 7.5 }); 
        this.label[1].attr({ "font-weight": 800 }); 
       } 
      }, function() { 
       this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce"); 

       if (this.label) { 
        this.label[0].animate({ r: 5 }, 500, "bounce"); 
        this.label[1].attr({ "font-weight": 400 }); 
       } 
      }); 
     }; 

回答

1

它無法看到你的所有代碼。所以我只能猜...

也許這部分是撥錯

this.sector.scale 

這部分代碼,也許有一些值HAVA一些DOM參考。當函數得到結束時,該值仍然不釋放DOM引用。