How does babylon free up memory quickly when a page is unloaded

You can’t directly free-up DOM GC but you can help memory management with removing references and objects, which may result in faster GC. If you’re removing <iframe> elements then you’re doing all that’s required for GC. It may be taking 15 seconds because the browser is utilising thread memory bandwidth to keep a smooth browser experience; it may also be considering to keep resources in memory if you re-visit any resources in a short time, which can be likely if a user “re-opens” a tab (this is my conjecture). Also note experience will differ across browsers.

If you’re re-creating <iframe> elements in a short amount of time then I would imagine you may eventually get performance/memory heap spikes. Also DOM Renderers can be shared across <iframe>'s if the same browser tab + domain, thus could hold-up its parent and children trees rendering. I have a feeling Facebook may be taking advantage of this as they like to use <iframe>s.

I would ignore DOM GC and concentrate on JS GC for Babylon testing. Store the <canvas> and engine refs in a top-level state class and any app related variables (as const or let) here too. Also any DOM elements you may create you will want to manage them here too because any references to these can prevent GC. You may create a function in the class to null/clear variables as required.

3 Likes