How to dispose and destroy GLTF object completely

Hi everyone,

I know there are some topic about this issue. I tried most of the things but failed. I think im missing a small detail but i can’t see it.

In my scene im removing a GLTF and load another GLTF. I have a function to remove models. And the code is like this.

mC3DGLTF.scene.traverse(function (obj) {
    if (obj instanceof THREE.Mesh) {
      obj.geometry.dispose();
      obj.material.dispose();
      mC3DGLTF.scene.remove(obj)
      console.log(obj)
    }
  });
  mScene.remove(mC3DGLTF.scene);
  mRenderer.renderLists.dispose();

The model in the picture has pillows. And you can click pillows to change color. After clicking the pillow you get a message as in the picture.

After removing the model i load another model and it doesnt have any pillow. But when i click at the position of previous pillow i get the same message as if pillows were still there. I think they are still there but just can’t see them.

How can i solve this problem. Could you please help me?

This line should not be necessary. However, if you call material.dispose(); it’s also required to dispose any of its textures. Since textures can be shared across materials or reused at a later point, you have to do this separately (meaning it does not happen automatically when calling material.dispose();).

Besides, it sufficient to remove the asset from the scene like so:

mScene.remove(mC3DGLTF.scene);

mC3DGLTF.scene.remove(obj) can be deleted.