[Help] Can't dispose Texture and free up renderer memory (instead dispose geometries works)

hi!
I try to clean up the memory of my rendered.

Each time I change the model in my scene I remove the old model and I dispose the old geometries and the old materials in this way:

scene.remove(model)
meshes.forEach((mesh) => {
  mesh.geometry.dispose()
  mesh.material.dispose()
})

But if I check the renderer.info I see the number of the geometries and textures grow up.

In the picture below I print the memory status when I add a new object and when I remove the old:

So my question is:

how to find and dispose textures from a scene?

Thanks in advance and kind regards,

Davide

Try this:

scene.remove(model)
meshes.forEach((mesh) => {
  mesh.geometry.dispose();
  mesh.material.forEach((tex) => { tex.map.dispose(); }
  mesh.material.dispose();
})

Hi @Chaser_Code thanks for reply!
Unfortunately It return me an error because my materia il not an array:
Screenshot 2022-01-21 at 11.52.02

then I try without success this:

meshes.forEach((mesh) => {
    mesh.geometry.dispose()
    mesh.material.map.dispose()
    mesh.material.dispose()
  })

Maybe I missed something ?!

Thanks and regards,

Davide

@Chaser_Code
I tried to dispose the texture object and not the map of the mesh and It works:

const texture = new THREE.CanvasTexture(canvas)

// Correctly disposed
texture.dispose()

But about your answer I wonder if it’s possibile to add more materials to a mesh because it could be useful in my case.

Thanks in advance and kind regards!

Davide

You can improve code for future. Add checking is one material or several. Checking have it map, aoMap, lightMap etc and dispose them.