VR Removing GLTF

Hi.

Although there are some questions before about related issues like :slight_smile: Add/Remove scene object geometry memory leak related - #6 by PompiJs

I am using the most recent version of threejs and rendering a scene in VR(Oculus quest 2) using also react. I add a glb object but when unmounting scene or clicking on a 3D button to remove the object I execute twice something like this:
object3DChildren.map(obj =>{
if (obj instanceof THREE.Mesh) {
obj.geometry.dispose();
obj.material.map?.image?.close?.();
obj.material.map?.dispose();
obj.material.map.needsUpdate = true;
obj.material.dispose();
object3DScene.remove(obj)
}
});
I later check that the scene is actually clean, but after 3 times of the object properly being rendered and removed. It doesn’t render anymore and oculus gives a memory leak error related to the GLTFLoader. I even use useRef to make sure there is only one instance of the object and scene being rendered and removed. Does anybody know. a workaround for this?. Thank you.

Does the same thing happen if you try it on a normal webpage? Are you confident that you understand what R3F is doing well enough that it is doing what you want? How are you checking the scene is properly cleaned up? Have you tried looking at the renderer info? Or adding stats.js to the page to check the memory usage (idk if it will work on Quest)?

I would try checking if your R3F code works properly on a normal webpage. If it is, then try to create a minimal VR example where all you do is load the model / dispose of it, using vanilla THREE.js without react.

Hi.

Thank you for your answer. I am not using R3F, I’m using regular react. I am checking the scene before, during and after the cleaning execution finding that the object was actually removed. This is the issue that I’m seeing. This is not happening in a regular webpage view of the project, it only happens in 360 mode in the oculus explorer.
I first get:
THREE.GLTFLoader: Couldn’t load texture blob: https…
Then

I’m going to test the renderer info and stats.