TLDR Web Dev · ARTICLES & TUTORIALS

SNEAKY REACT MEMORY LEAKS: HOW USECALLBACK AND CLOSURES CAN BITE YOU

schiener.io9 min read

Summary from the TLDR Web Dev newsletter

Closures combined with the useCallback hook in React can cause hidden memory leaks by holding onto large objects in the component's context, preventing garbage collection. Memoized functions may inadvertently reference each other and shared data, creating an endless chain of closures. To avoid such issues, keep closure scopes small, avoid unnecessary memoization, and consider using useRef for large objects.