使用带悬停的raphael.js进行内存泄漏

Memory leak using raphael.js with hover

本文关键字:内存 泄漏 js raphael 悬停      更新时间:2023-09-26

使用带有悬停属性的Raphael库饼图时发生了严重的内存泄漏。如果我删除了包含悬停属性的代码,效果会很好,当我将其添加回内存占用时,内存占用会稳步增长,而悬停在饼图上会增加内存占用。与大多数其他示例不同,我使用window.setInterval不断更新页面(如果这有帮助的话)。我不知道如何纠正这个问题并寻求帮助。

以下是我正在做的基本工作。。。使用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 });
                }
            });
        };

它无法查看您的所有代码。所以我只能猜测。。。

也许这部分是

this.sector.scale  

这部分代码可能得到了一些具有DOM引用的值。当函数结束时,该值仍然没有释放DOM引用。