Destroying viewer with 3d tiles doesn't release memory

Hi all,

I am working on a project with 3d tiles. My problem is that once 3d tiles are loaded, viewer.destroy() doesn’t release memory. It looks like the memory never freed. I don’t think it is a matter of 3d tile data since I see the same issue with different 3d tile sets.

To replicate the issue, press a “go” button on the Sandcastle. Whenever the button is clicked, a new 3d tile is loaded. Memory usage keeps increasing and never released. Is there any way to release the memory?

first_load.JPG last_load.JPG

I appreciate your help in advance.

Sandcastle example:

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=zVRdT9swFP0rVh9okIrz3SRdQWMwbZX4ElSTpnWaTHJLLRwb2U6AIf777CSFlqKpe1vyYMc+955zj69TE4lqCvcg0T7icI+OQNGqxN+aNaefN59HgmtCOcj+7ocZt6/roivQSC8AUU41JQzlpARJmmxIC8SEuEVEo1PCF0RrYoJqQ9ahL4Qyo+CGtWM8IlKbGeEhnktRHsONBFDOXhJhz09TP/SC1POCKB2gyMPDzPejMAwTP0oDf4CSOLTSVhjOJQWjuiNZKe0rkILymwuq88WlYGyNLvBxkKRJliZpkIVpGA/QnlkLozDz4thLkyAaGjoPe4k/zGI/M9KyNPLjhr0xDascOODWDqxAWy+dpxlH5ilAacobVaO3XgxaiHgVPnqnmA4FvJhKwtVcyHK0LO2UaEkfIjw5/nw2nUy/z/jz8sCsM5oyWPeiHcLjqdkxSp0nVEn2km4i+CUoUckcGpMOlcFMCidOIn+307HFU5IHWlblWVVegzyfnwhSQNEwjpD3vGHcnaSlKboGhUlROFZ0W8QV4UVOlGZgN6ZCsGsiP1VaC+70v4j+AM0rnluPnN3Obtdtx47AeGgym8QSSlHDIWOOTb2C2JCwPfLX69yY/OPnGtysdJOdnWUG2wtSPL4kfk/y9rdyQ9r7DbhlE27fiP/QjBb6vNT63zbj3854tSFRe2YmpjfojZV+ZHDQrn6k5Z2Q2sp3MHY1lHeMmJ+be13lt6BxrpRNMHaXQeOC1ogW+7Pem5Od9VDOiFJmZ14xdkV/w6x3MHYNfi2Mieafdl6DZOTRQhb+wUm7iDEeu+ZzM0q3V2gl4x8

You might consider caching the viewer, and removing the tileset (perhaps you can hide the canvas element when you need it to be removed). There are some known issues with trying to recreate the viewer and the browser not letting resources go:

https://github.com/AnalyticalGraphicsInc/cesium/issues/5462#issuecomment-415822533

This modified Sandcastle seems to correctly garbage collect when removing the tileset.

Thank you for your help, Omar.

Your workaround works in the Sandcastle. But, in my project, the cesium canvas is embedded in a Bootstrap modal which is called using ajax. It is supposed to create a new viewer for a new cesium canvas whenever a new modal is shown.

Our team has spent a lot of time and effort to prepare 3d tiles and utilize them within our product. Now, we get stuck because of the memory leak issue. I would really appreciate if you run into any solutions and share with me.

Perhaps you could write a wrapper around the Cesium viewer, so its “destroy” function just hides it and removes all primitives, instead of completely removing the viewer? And then you can pass this custom object to your Bootstrap modal instead of passing the Cesium viewer directly.

Let me know if that helps. What kind of project is this for?