Viewer and Scene destroy

Just looking for some clarity.

Is it necessary to destroy the scene as well as the viewer in order to release WebGL resource? Or does destroying the viewer also destroy the scene? Taking a look at the source code for the destroy method on the Viewer, it doesn’t look like the scene is being destroyed, unless I’m missing something.

Also, it looks like there is no need to destroy new primitive collections / individual Tilesets that have been added to the scenes primitive collection, as all primitives added to the scene get destroyed on the scene.destroy() method, correct?


Thank you for your questions! Memory management in CesiumJS is not my specialty, but I will try to help you out as much as possible. As always, input from the rest of the community is welcomed. Some comments from my end:

  • If you look through our source code, you will see that Viewer actually creates a CesiumWidget, which initializes a Scene.
  • Thus, destroying the Viewer, destroys the CesiumWidget, which destroys the Scene. You may be able to destroy the scene directly through the CesiumWidget object.
  • The simplest way to release the WebGL resource would be to destroy the Scene.
  • scene.destroy() will indeed remove all the primitives added to the Scene.

Please let me know if you have any other questions or concerns. Looking forward to hearing your thoughts.


That’s great thanks for your quick reply, didn’t notice that the widget held the scene.
Thanks again!

1 Like


Of course! I am happy to help out.