How to free up render memory?

Hi everyone!

I am working on glTF loader to load multiple files.
However, I am stuck in how to free up memory of the render.

Follow up here (https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects), I tried to dispose all geometry, texture and material whenever I change to load another models, but still have problem in render memory.

According to the first pic (for the 1st model), the render.info.memory.geometries = 15
But when I load the 2nd model (the second pic), the render.info.memory.geometries = 32
Actually the 2nd model only has 17 geometries and the 1st model has 15 geometries.

Thanks,

Could you share the code you’re using to dispose of objects, or a demo?

Hi @donmccurdy,

Here is how I use to dispose all the things:
// Clean up
mesh.children.forEach(child => {
child.traverse(function(obj) {
if (obj.type === 'Mesh') {
obj.geometry.dispose();
obj.material.dispose();
obj.texture.dispose();
}
})
});

Thanks,

Are you seeing any errors in your JS console? I would expect that code to throw an error; obj.texture is not a property. You may also want to check obj.isMesh instead of obj.type === 'Mesh', in case your file has a SkinnedMesh in it.

I didn’t see any error in the console.
But you’re right, I should check obj.isMesh() instead.
Maybe this makes me cannot free up the renderer memory? Since when I check the renderer.info whenever I change another models, the renderer memory increased continuously.
(You can see the pics I uploaded above).

Thanks,

Sorry, I’m not able to debug from these pictures. The code above would throw an error if it were running, and that error would appear in the console. If there is no error shown and the code is not running, then there seems to be some mistake elsewhere in your demo.

Thanks @donmccurdy,

I finally catched the error that would throw in the console since obj.texture is not a property as you said.
Plus, I follow up this tutorial (https://threejsfundamentals.org/threejs/lessons/threejs-cleanup.html) to dispose the geometry and material and so on.

However, when I check the renderer.info.memory, the {geometries: 18, textures: 38} values still increased continuously.

Sorry, I am going to make a record for what I am doing and upload in this thread soon.

I’m seeing similar increase of renderer.memory.textures which I reported here.
I placed an example in jsfiddle (plays in Chrome).
I don’t know if this is a problem though.