firtoz / react-three-renderer

Render into a three.js canvas using React.
https://toxicfork.github.com/react-three-renderer-example/
MIT License
1.49k stars 155 forks source link

Are textures deallocated when removed from render tree? #162

Open nickpolet opened 7 years ago

nickpolet commented 7 years ago

I have a project that involves dynamically loading lots of textures into a scene when needed. I am slightly worried that loaded textures will not be deallocated with renderer.deallocateTexture( texture ) when the mesh and material is not in the render tree.

Is this something that I will have to do manually, with something like:

this.refs.renderer.deallocate(this.refs.texture)

before the mesh and texture is removed from the scene? This could be done in the componentWillUnmount function which is actually quite a tidy place to have it.

Just thought I'd check before powering on and implementing it.

Thanks.

toxicFork commented 7 years ago

When a texture gets unmounted it does call .dispose which I'm hoping should trigger the deallocation, but I'll try to dig deeper , run some tests with breakpoints and confirm how it exactly works and if the deallocations happen properly.