API

Reducing Memory Footprint

Babylon.js offers multiple options to reduce the memory usage of a scene:

Turning off IndexedDB

By default, all assets are saved in the local IndexedDB to reduce network calls when loading the same files multiple times. This feature uses memory so you can turn it off at engine level with:

engine.enableOfflineSupport = false;

Turning off support for context lost / context restore

Babylon.js will automatically recreate everything in a transparent way if the WebGL context is lost. While handy, this feature consumes a lot of memory, so you may want to turn it off when creating the engine with:

import { Engine } from "@babylonjs/core/Engines/engine";
var engine = new Engine(canvas, true, { doNotHandleContextLost: true });

You can also turn it off after engine creation (but before creating any resources) with:

engine.doNotHandleContextLost = true;

Removing cached vertex data

All vertex buffers keep a copy of their data in CPU memory to support collisions, picking, geometry editing, or physics. If you don't need to use these features, you can call this function to free associated memory:

scene.clearCachedVertexData();

Removing cached texture buffers

In order to be able to serialize or rebuild them, all textures keep an internal buffer of the original source (this could be a string if you used a URL, but it could also be a buffer if you used a blob). If you don't need to use these features, you can call this function to free associated memory:

scene.cleanCachedTextureBuffer();

You can find a demo here: Reducing Memory Footprint Example