在循环(JavaScript)中调用Plotly.plot()时发生内存泄漏

我也将其发布在密谋论坛上,但该论坛似乎并不活跃...

大家好,

我在更大的Asp.Net Webforms应用程序(也使用了telerik控件)中使用plotly.js,偶然发现内存泄漏(在IE11中进行了测试)。我尝试了不同的方法,并创建了一个小示例(请参见下面的代码)。在代码中,我创建了一个具有4000x4000个随机数据点的直方图,并在循环中将它们绘制了10次(按“重新绘制轨迹”按钮)。我希望下一个迭代中的新plot()调用仅“覆盖”之前迭代的图。但是内存使用量会增加,直到我用完内存...

删除整个图或调用GC都无济于事(内存减少了一点)。

任何人都有类似的问题,并且知道如何处理此问题。有没有一种方法可以完全重设/清除图而无需重新加载整个页面(因为在我的大型应用程序中,我使用的是Ajax,并且每次都无法重新加载整个页面)?

谢谢!

<head>
  <!-- Plotly.js -->
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
  <div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
  <div id="delete" style="margin-left:80px;">
      <button style="background: red;" onclick="deletePlot()">Delete/Purge</button>
  </div>

  <div style="margin-left:80px;">
      <button style="background: green;" onclick="plotAll()">Replot Traces</button>
  </div>

  <div style="margin-left:80px;">
      <button style="background: blue;" onclick="CallGC()">Call GC</button>
  </div>

    <script>
        function deletePlot(){
            Plotly.purge('myDiv');
        }

        function plotAll()
        {
            var n = 4000

            var s2dArray = '[';
            for (var i=0; i <n; i++)
            {
                s2dArray = s2dArray.concat('[');
                for (var j=0; j <n; j++)
                {
                    s2dArray = s2dArray.concat(Math.round((Math.random() * 100) + 1));
                    if(j < n-1)
                    {
                        s2dArray = s2dArray.concat(',');
                    }
                }
                s2dArray = s2dArray.concat(']');
                if(i < n-1)
                {
                    s2dArray = s2dArray.concat(',');
                }
            }
            s2dArray = s2dArray.concat(']');

            var data = [
            {
                z: JSON.parse(s2dArray),type: 'heatmap'
                }
            ];

            for(var i =0; i<10; i++)
            {
                Plotly.plot('myDiv',data,{},{showSendToCloud: true});
                console.log(i);
            }
        }

        function CallGC()
        {
            CollectGarbage();
        }
    </script>
</body>
a125000178 回答:在循环(JavaScript)中调用Plotly.plot()时发生内存泄漏

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3158055.html

大家都在问