4

I'm writing an app that makes use of JointJS to display diagrams.

However, I want to be able to dynamically add and remove diagrams from a page. Adding new diagrams is fairly trivial, but when I remove diagrams, is it safe to remove the DOM elements and let the graph and paper objects get garbage collected?

SpoonMeiser
  • 19,918
  • 8
  • 50
  • 68

1 Answers1

6

Yes, that's almost it. Better yet is to call graph.clear() (to remove all the cells from the graph and their associated views from the paper) and then paper.remove() (to cleanup the paper from the DOM, including its event handlers).

dave
  • 4,353
  • 2
  • 29
  • 25
  • I am trying to delete/remove all the elements from the graph. When I do it as below, only links get removed and while removing other svg elements, it throws below exception: Uncaught TypeError: Cannot read property 'unembed' of undefined I tried to achieve it with graph.clear(); but because the above did not work I tried as below: var cells = graph.getCells(); for(i = 0; i < cells.length; i++) { graph.getCell(cells[i].id).remove(); } Both the ways I get this error message: Uncaught TypeError: Cannot read property 'unembed' of undefined – Puneet Pandey Dec 10 '17 at 07:03