Deal with memory leak in gojs diagram


I’m struggling with memory leaks in gojs diagram. I have made the diagram and its node/link templates out of the loop. The diagram uses same HTML tag. Within the loop i just make my desired nodes and links in object forms and then assign them to diagram.model.nodeDataArray. In DevTools of chrome in memory profiling timeline I clearly observe remained vertical blueline in any interval.

var nodes = [];
function loop()
diagram.model.nodeDataArray = [];
diagram.model.nodeDataArray = nodes;
nodes = null;


The only obvious reason for memory retention is that the UndoManager has been enabled. Is that the case?

It’s odd that you are setting Model.nodeDataArray twice. But that shouldn’t matter with respect to memory usage.

I assume you are wanting to load a new diagram upon each successful response. What is normal and easiest is to create a new Model and then assign Diagram.model. Nothing else is needed. Most of the samples demonstrate this.


I just set animationManager.Enable to true. In any interval i want to update all elements of the diagram. Of course there are others items in any node object and i just wrote the key and text above.
I’m afraid maybe nodes variable doesn’t completely remove from memory.


There would be a reference to the same array from diagram.model.nodeDataArray, so the nodes variable is just another reference to that same Array.

So, if you have not enabled the UndoManager and you have changed your code not to use the nodes variable and to just replace the Diagram.model each time, do you still have a memory problem?


Sorry. I’m out of the time of working day. Tomorrow i will test your suggestion.
Thank you


If data is just the Array of node objects, your code could just be:

success: function(data) {
  diagram.model = new go.GraphLinksModel(data);

But I don’t know if you are using a GraphLinksModel or a TreeModel or a plain Model, so you would need to use the desired class.