3 ms·
One thing to watch out for currently are memory leaks that retain previous state even if unmounted and/or unrelated. I’ve seen several bugs especially with use
by sbr464 7y ago
One thing to watch out for currently are memory leaks that retain previous state even if unmounted and/or unrelated.
I’ve seen several bugs especially with useRef/memo, and animation related hooks, or hooks that combine several together to expose a simpler api.
I didn’t notice them until working with larger file uploads and local content. They can be hard to spot with small changes, Since they are usually deep in the memory trace stack.
The component with the bug doesn’t need to even be in the tree to accidentally retain state that you’ve cleared/unmounted.
Since then I’ve made a simple test that saves a large test blob to local state, and makes sure it gets garbage collected etc, not stuck in another components previous state memory snapshot.
—
An example could be a loading animation above/outside the tree, that uses a hook somewhere inside its library that tracks browser size changes. It wouldn’t seem to affect you, but it could inadvertently cache some state in the window. So you’d only detect it if you’re working with very large content.