title: Memory leak when calling Plotly.plot() in a loop (JavaScript)
body: <p>I posted this on the plotly forum as well, but that forum does not seem to be very active...</p>
  
  <p>Hello everybody,</p>
  
  <p>I am using plotly.js in a bigger Asp.Net Webforms application (telerik controls are used as well) and stumbled upon memory leaks (tested in IE11). I tried different things out and created a small example (See code bellow). In the code I create a histogram plot with 4000x4000 random data points and plot them 10 times in the loop (Press the “Replot Traces” Button). I would expect that the new plot()-call in the next iteration just “overrides” the plot of the iteration before. But the memory usage increases until I run out of memory...</p>
  
  <p>Deleting the whole plot or calling the GC does not help (the memory decreases just a little bit).</p>
  
  <p>Did anybody have similar problems and has an idea how to handle this. Is there a way to completely reset/clear plotly without reloading the whole page (because in my big application I am using Ajax and cannot reload the whole page everytime)?.</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>&lt;head&gt;
    &lt;!-- Plotly.js --&gt;
    &lt;script src="https://cdn.plot.ly/plotly-latest.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="myDiv"&gt;&lt;!-- Plotly chart will be drawn inside this DIV --&gt;&lt;/div&gt;
    &lt;div id="delete" style="margin-left:80px;"&gt;
        &lt;button style="background: red;" onclick="deletePlot()"&gt;Delete/Purge&lt;/button&gt;
    &lt;/div&gt;
  
    &lt;div style="margin-left:80px;"&gt;
        &lt;button style="background: green;" onclick="plotAll()"&gt;Replot Traces&lt;/button&gt;
    &lt;/div&gt;
  
    &lt;div style="margin-left:80px;"&gt;
        &lt;button style="background: blue;" onclick="CallGC()"&gt;Call GC&lt;/button&gt;
    &lt;/div&gt;
  
      &lt;script&gt;
          function deletePlot(){
              Plotly.purge('myDiv');
          }
  
          function plotAll()
          {
              var n = 4000
  
              var s2dArray = '[';
              for (var i=0; i &lt;n; i++)
              {
                  s2dArray = s2dArray.concat('[');
                  for (var j=0; j &lt;n; j++)
                  {
                      s2dArray = s2dArray.concat(Math.round((Math.random() * 100) + 1));
                      if(j &lt; n-1)
                      {
                          s2dArray = s2dArray.concat(',');
                      }
                  }
                  s2dArray = s2dArray.concat(']');
                  if(i &lt; n-1)
                  {
                      s2dArray = s2dArray.concat(',');
                  }
              }
              s2dArray = s2dArray.concat(']');
  
              var data = [
              {
                  z: JSON.parse(s2dArray),
                  type: 'heatmap'
                  }
              ];
  
              for(var i =0; i&lt;10; i++)
              {
                  Plotly.plot('myDiv', data, {}, {showSendToCloud: true});
                  console.log(i);
              }
          }
  
          function CallGC()
          {
              CollectGarbage();
          }
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>