When the user quit the game to go back to the menu, I destroy the application using application.destroy. Then, when the user start again the game, I create a new Application.
I am using Vue.js so it’s done without page reloading and Playcanvas is keeping all the objects in memory even after I destroy the application (MeshInstance, GraphNode, etc…).
Is there a clean way to free the resources of an application or a scene ?
unloading an asset destroys it’s resource, it does not remove it from the asset registry. You must also call app.assets.remove(asset) for each asset in the registry.
(Though I think app.destroy should do this for you)
I tried calling app.assets.remove(asset) before app.destroy(), but I still have all the Mesh, MeshInstance and GraphNode retained by playcanvas in memory.
For now, the only way I found to reduce the leak is to remove the mesh instances manually:
(this.app.assets as any)._callbacks = {};
(this.app as any).lightmapper = null;
this.app.batcher = null as any;
And some MeshInstance are still retained by window.pc.Scene.defaultMaterial.meshInstances, window.pc.Scene.defaultMaterial._scene._layers, and window.pc.ModelHandler.DEFAULT_MATERIAL._scene._layers.