Scene Start/Stop Memory Leak

The concern

I am experiencing a memory buildup whenever I switch back and forth between two scenes. I use Firefox DevTools memory snapshots to determine that the buildup happens. I am manually triggering garbage collection in my browser (about:memory) everytime I switch back and forth. I trigger it before taking the snapshots.

Each time I switch back and forth between two scenes, I gain around 8 MB. My assets in total are around 2.5MB.

The code

I am switching back and forth between some scenes, say SceneA, SceneB and SceneC.

scene.start is used for this, meaning the scene that starts gets stopped.

I have a PreloadScene that start SceneA. All assets are preloaded from the preloadscene. Nowhere else does asset loading happen.

In the scenes, I listen for the shutdown event to then null all properties directly on the scene object. The code works.

The question

What else can I do to ensure no memory leaks are happening?

Thank you

I found the solution: Removing the stopped scene frees memory.
Afterwards, the scene has to be re-added, so that it can be started again.

This way, 0 memory footprint. I trigger garbage-collection and snapshot shows constant 16MB after each scene switch.

Garbage-Collector is lazy though, but that’s probably by design