WebGLRenderer: Calling dispose() does not trigger dispose() on geometries, materials etc.
See original GitHub issueEach time Pass.FullScreenQuad
is used in a new WebGLRenderer, a dispose
listener is attached to geometry
. But when WebGLRenderer is disposed, geometry
is not disposed, therefore the reference to the dispose
listener is retained.
The listener holds a reference to info
and bindingStates
, which further refers to many other objects.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
How to dispose of objects – three.js docs
No, you have to explicitly dispose the geometry and material via dispose(). Keep in mind that geometries and materials can be shared among...
Read more >Three.js: how to correctly dispose a scene in memory
Calling dispose on the materials, and geometries does not clear memory fully. Removing mesh from scene doesn't clear fully. And removing console ...
Read more >The Big List of three.js Tips and Tricks!
Always try to reuse objects such as objects, materials, textures etc. (although updating some things may be slower than creating new ones, see...
Read more >Three.js Cleanup
You free three.js resource this by calling the dispose function on textures, geometries, and materials. You could do this manually. At the start...
Read more >Automatic disposal | React Three Fiber
dispose() , if present, on all unmounted objects. If you manage assets by yourself, globally or in a cache, this may not be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess one question is whether or not there’s another way to approach this that affords using two renderers at once or will it always be impossible to fully dispose of one renderer without incurring a reinitialization cost of shared geometry in the second.
One approach would be to enable disposing of objects directly on the renderer itself rather than with a dispose function:
Or of course using a
Map
rather thanWeakMap
in WebGLGeometries. What is the benefit of using a WeakMap right now? It will let the geometry objects be garbage collected in JS but it will never allow for the gl bindings to be disposed of which will leave unreferenced VAOs in memory until the renderer is disposed of.I guess it seems like there’s never a case where a user should feel comfortable with letting a BufferGeometry get garbage collected without calling dispose except for maybe just using a single renderer and having just disposed of the renderer. But even then they have to be sure that all of the geometry is left unreferenced or the renderer context can’t actually get cleaned up. If users are being told to call “dispose” on something it should actually properly dispose of the object. Are there strong feelings against using a
Map
rather thanWeakMap
in WebGLGeometries (and similar classes)?Maybe WeakRef will make this all a bit simpler but we’ll see. In the mean time I can look into clarifying the wording on WebGLRenderer.dispose.
Yes, this is intended. You’ve already pointed out the reason (non-iterable WeakMaps) for why this is the case.
Improving the docs is always good!