Automatic disposal
Freeing resources is a manual chore in three.js
, but React is aware of object-lifecycles, hence three-fiber will attempt to free resources for you by calling object.dispose()
, if present, on all unmounted objects.
If you manage assets by yourself, globally or in a cache, this may not be what you want. You can switch it off by placing dispose={null}
onto meshes, materials, etc, or even on parent containers like groups, it is now valid for the entire tree.
const globalGeometry = new THREE.BoxGeometry()
const globalMaterial = new THREE.MeshBasicMaterial()
function Mesh() {
return (
<group dispose={null}>
<mesh geometry={globalGeometry} material={globalMaterial} />