-
When I swap GLB models they are cached and immediately loaded when needed, it's great for speed however if the number of models I swap is many then a lot of unused data is accumulated in the memory. I wonder if it's somehow possible dispose of the data of the GLTF/GLB model when the component is unmounted? ...
const model = useGLTF(url)
useState(() => {
return () => {
model.dispose() // ?
}
}, [url])
return ... It would also be a great feature to add a cap for memory ot number of cached items maybe. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
import { dispose } from '@react-three/fiber'
function Foo() {
const { scene } = useGLTF(url)
useEffect(() => () => scene.traverse(dispose), []) dispose is a small helper that we export https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/web/index.tsx#L159 but you can dispose it yourself any way you want. |
Beta Was this translation helpful? Give feedback.
dispose is a small helper that we export https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/web/index.tsx#L159 but you can dispose it yourself any way you want.