I’m loading gltf models continuously when I check the memory usage by hovering the chrome tab it is very high.
I tried disposing of the objects by following the documentation but there is not much improvement.
The first image is the memory snapshots I took, the first snapshot is before reloading the page. the second is the memory usage. the last snapshot is after calling the dispose function.
the second image is memory usage of the chrome tab.
I am not sure whether these two images have any relation or this occurs from three.js but I wanted to check if anyone has any idea about this.
dispose disposes only the resources allocated on the GPU. You seem to be having a CPU memory leak - ie. you’re storing the references to loaded objects somewhere in the memory, preventing garbage collector from throwing them away. You can expand the trees in the memory snapshot to find the specific reason behind the memory leak.
(On a side-note - you can use dispose only after you remove the element from the scene. If you call dispose, but the objects are still in the scene - it won’t do anything.)
Disposal does not have anything to do with the memory you’re looking at. Dispose disposes assets from the GPU. The memory snapshots you’re sharing are CPU memory / JS heap stack.
Make sure you’re not storing your meshes in any arrays, besides scene.children (I mean, you can and often need to, but you have to remember to remove the meshes from said arrays - otherwise they remain in memory forever.) Meshes stored in arrays that are used during the runtime will not be removed from memory until the mesh is removed from said array.
Make sure you’re not assigning meshes as properties of other meshes / objects - ex. object.characterMeshRef = myMesh - this mesh will not disappear from the memory until you unassign it from that property - ex. object.characterMeshRef = null.
Do not console log stuff when measuring the memory. References expanded in the console remain in-memory.