How to dispose a texture from the renderer - renderer.info.textures increases with replacement of texture

In three js I’m seeing WebGL out of memory errors on my iOS devices.
The web-app runs ok on various other OSs and browsers e.g. Windows/Linux/MacOS, Firefox/Chrome/Safari, but maybe the problem is just hidden, and exacerbates on the weaker iOS devices.

I saw this link. In my case the renderer.info.textures number keeps growing with every image.

Is this ok, or should I dispose the previous texture? If yes how?
In the rendered scene I see only one Sprite object with single material image texture.

Thanks

Without more context it’s hard to recommend something. Consider to demonstrate the memory leak with a live example.

That said if you don’t need a texture anymore, call dispose() on it.

I created an example. (it plays in Chrome)
In the console, renderer.info.memory.textures grows with every added image.

According to here renderer.info.memory.textures indicates the number of “Textures in Memory” ?
In my case, I don’t need to keep previous textures in memory.

I also found this link which:

  • disposes the geometry and the texture of the object before removing the object from the scene, and
  • disposes the renderLists

But renderer.info.memory.textures still grows…

Thanks

2 Likes