Fix React Memory Leaks: Subscriptions, Timers, Closures

Your React app's heap grows the longer it runs. This guide names the four leak sources — unclosed subscriptions, uncleared timers, closures holding refs, and detached DOM nodes — shows you how to confirm each one with a Chrome DevTools heap snapshot, and fixes every pattern with before/after React…

Your React app leaks from four places, and only four: subscriptions that never close, timers that never clear, closures that hold references, and detached DOM nodes nobody released. The fastest way — how to check and fix memory leaks in React applications — is the heap-snapshot comparison: Chrome DevTools → Memory tab → take a heap snapshot → repeat the suspicious action ten times → click the trash icon to force garbage collection → take a second snapshot → switch the view to "Comparison" and look for a positive # Delta or nodes filtered as "Detached". If the delta is ~0, you're clean. If it's positive, one of the four sources below is your culprit. Code is React 19.2. Note: React 18 removed the old unmounted-component warning — React won't flag this for you anymore. What the leak looks like: how to check and fix memory leaks in React applications A memory leak has one observable symptom: the heap grows while the user repeats the same action , and forced GC doesn't bring it back down. Open Chrome DevTools (F12) → Memory tab and run this exact procedure: Take a heap snapshot (baseline). Perform the suspected action 5–10 times — open and close a modal, switch tabs, navigate to a route and back. Click the trash icon to force garbage collection. Take a second heap snapshot . Change the view dropdown from "Summary" to "Comparison" and compare against snapshot 1. A healthy app shows # Delta near zero. A leaking app shows the same constructor names with a large positive delta — your components, WebSocket , EventSource , Closure . Then filter by "Detached" : Detached HTMLDivElement nodes were removed from the document but are still referenced by JavaScript — the smoking gun of a retained chain. The same inspect-measure-verify discipline applies on other…

Explore