Remove the assets (GLB models) from the cache memory associated in the chrome

Our vision was to only load the models which are closer to the camera. The objects which are far away from the camera should be removed automatically (if it exist in the scene) to optimize the scene. The problem is that even though it is removed from the scene it is not yet removed from the cache memory of the chrome.

I have seen the decenterland which is made in Unity do this technique. The assets are removed from the RAM when the camera is far away. I was thinking if that is possible in Babylon.js.

What happens if the objects become visible again in the camera field some time later?

The engine will have to display them again, so they can’t be deleted from memory (you probably don’t want to reload them every time they become visible again!).

The idea is to clear the render memory and only store the asset in memory so that u wont have to download the asset again when it comes to view
the reasoning is the area we are trying to create is a quite large one.
One that is similar to decentraland (https://decentraland.org/). And when loading dynamically memory is becoming a concern when we are storing all those assets in uncompressed form.
So i wanted to know if there is any way to manage memory similar to unity heap when u can allocate and deallocate the memory.
Rerendering the assets again is not a big overhead currnetly .

They’re probably using LOD techniques, see: Levels of Detail (LOD) | Babylon.js Documentation (babylonjs.com)

You can also use the dispose() method on the meshes that are far away from the camera, which will remove them from the scene and free up the memory

1 Like

you need to research how garbage collection works in browsers , since you mention chrome. Javascript does not expose a means to force a GC sweep. If your objects get dereferenced properly , they can be marked by the GC to be cleared and will eventually be cleared at some later point.

1 Like

Hi thanks for the reply, I have researched about the garbage collection and was able to release the heap memory of JavaScript of the GLB model(24MB). The problem is that RAM usage of nearly 1.1GB (associated with the GLB model rendering and loading) is still not getting removed after disposing the model itself. The only way to release the RAM is to dispose of the engine of babylonjs. Even after disposing the scene the RAM usage is not getting released. Is there any other way to achieve the same result.

How do you check the Javascript heap size? The GC is free to not reclaim memory right away, even if the app released it. One way to force the GC to reclaim memory is to click on the “Collect garbage” button of the “Performance” developer tab (in Chrome).