Memory leaks

After loading the charts multiple times , JS Memory keeps on increasing , resulting to memory leaks.
On destroy i am handling graph clear (graph.clear() and model.clear() etc…), but still in some way not fixing the problem.
Any suggestions :)

Are you keeping the same HTML DIV element in your page and you are trying to reuse the same Diagram instance?

Normally one only replaces the Diagram.model when wanting to show a different diagram, because one wants to keep listeners on the Diagram in place. Or one replaces the DIV.

But if you really want to replace the Diagram, you’ll need to set Diagram.div to null, to disassociate the Diagram and the DIV element. And you’ll want to remove any listeners that you added to the Diagram. And of course you had better not be keeping any references to any GoJS objects: Diagram, Layer, GraphObject (including Node and Link), Tool, CommandHandler, AnimationManager, et al.

Yes i am keeping the same div element and reusing it .I am already setting Diagram.div to null as well.

OK, I have been running a simple test where I am reusing a DIV in a page but creating, showing, and then discarding a Diagram about 6 times a second.

As far as I can tell, the memory usage increases for a while and then decreases back to the original amount after a full garbage collection.

This is my basic code:

  var stop = false;
  function loop() {
    if (stop) return;
    var div = document.getElementById("myDiagramDiv");
    var diagram = go.Diagram.fromDiv(div);
    if (diagram !== null) diagram.div = null;
    init();
    setTimeout(loop, 150);
  }

BTW, I’ve set "animationManager.duration": 100 in the Diagram initialization, so that the animation can finish before the diagram is discarded. I’m not sure that matters.

The stop variable is just to make sure I can take memory snapshots at well defined times.