Browser memory heap size keeps increasing after using scene.dispose()

I have an app that allows loading of multiple scenes… Upon loading a new scene, I check if an existing scene exists and if so I dispose of it using scene.dispose(). This all works visually but when I look at the memory tab on chrome dev tools I see the totalJS Heap size keeps increasing until it eventually runs out of memory and crashes the browser.

Is scene.dispose actually not freeing up resources (meshes, textures, scene object…etc) correctly. Do I need to dispose the engine entirely . ?

here is a snipped of how im handling the scene disposal

function disposeScene() {
if(!scene) return;
return new Promise((resolve, reject) => {
scene.onDisposeObservable.addOnce(()=>{
resolve(scene);
});
scene.dispose();
});
}

async function newScene()
{
if(scene){
engine.stopRenderLoop();
await disposeScene();
}

scene = new Scene(engine);

}

Some resources are cached by the engine (like the compiled shaders).

To completely wipe all the resources, the ultimate way is to call engine.dispose() :slight_smile:

This is what I suspected, sounds like disposing the engine is probably best. Thanks for the response!

-Anupam

1 Like

Hmm. disposing the engine still is causing the heap size to increase. It seems to be occurring with only meshes/textures and not other scene elements like lights and cameras. I also tried disabling browser caching on chrome dev tools but having the same issue. I can also verify that it is infact caching the loaded assets because if I try to load the same scene twice, then my heap size does not increase and the scene loads faster the second time.

Is there some scene/engine caching configuration that I might need to look at. I will keep investigating but any tips would be welcome.

— code —

function disposeEngine() {
if(!engine) return;
return new Promise((resolve, reject) => {
engine.onDisposeObservable.addOnce(()=>{
resolve(engine);
});
engine.dispose();
});
}

async function newScene()
{

if(engine)
{
  await disposeEngine();
}
engine = new Engine(params.canvas);
scene = new Scene(engine);
scene.useRightHandedSystem = true;
scene.clearColor = new Color4(0,0,0,0);

}

Ideally I would need a repro in the playground to help you further

I can not repro on my local testing :frowning: @Anupam_Das could you provide a repro ?