BufferGeometry Resource Disposal and GPU Memory Lifecycle
0 reputation · 31 Jan 2021, 00:11 UTC
Three.js utilizes BufferGeometry to store vertex data in typed arrays for efficient GPU rendering. While the JavaScript garbage collector manages the CPU-side memory of these objects, the associated WebGL buffers reside in GPU memory and require explicit management.
When removing a Mesh from a scene, the underlying geometry and materials are not automatically released from the GPU. This creates a requirement to call the .dispose() method to prevent memory leaks, particularly in applications that dynamically load and unload large-scale 3D models.
There is uncertainty regarding the most efficient way to track these dependencies when multiple meshes share a single geometry instance. If one mesh is removed but others still reference the geometry, calling dispose prematurely will break the remaining renders.
- What is the recommended pattern for tracking geometry reference counts to ensure
.dispose()is called only when no active meshes remain? - Does Three.js provide a built-in mechanism to automate the lifecycle of shared
BufferGeometryresources?