memory leak
Memory that a program keeps holding although it no longer needs it, so usage grows until the program slows down or crashes.
In more detail
Common causes are timers, listeners and caches that are never cleaned up, and references kept to objects that are no longer needed. A garbage collector cannot free anything that is still referenced, so leaks happen even in languages with automatic memory management.
Examples
Typical browser leaks: forgotten intervals, listeners and MutationObservers never removed, and detached DOM trees kept in variables. WeakMap, AbortSignal and disconnect() help avoid them.In React apps leaks usually come from listeners, timers or subscriptions set up in an Effect without a cleanup function.Related terms
- detached DOM tree — DOM nodes that have been removed from the page but are still kept in memory because some JavaScript still references them.
- garbage collection — The automatic freeing of memory held by objects that the program can no longer reach.
- WeakMap — A key-value collection whose keys must be objects and are held weakly, so an entry disappears when its key object is garbage collected.
- closure — A function bundled with the variables it remembers from the scope where it was created.
- heap snapshot — A file recording every object in a JavaScript heap at one moment and how they refer to each other, used to find memory leaks.
- retaining path — The chain of references from a garbage-collection root to an object, showing why that object cannot be freed.
- cleanup function — The function an Effect returns so React can undo what the setup did, such as removing a listener or cancelling a request.
- event listener — A function registered with addEventListener that the browser calls whenever a given event happens on an element or on window.
- unmount — When React removes a component and its DOM nodes from the page, discarding its state.
- fault isolation — Designing so a failure in one part cannot take down the others.
- memory — The fast, temporary working space where running programs keep their data; it is emptied when the machine powers off.
Taught in
- MutationObserver: Reactive DOM Watching Without Polling — Frontend Architecture & Web Platform
- Event Delegation: Memory-Efficient Interaction Handlers — Frontend Architecture & Web Platform
- Memory Management: Garbage Collection, Memory Leaks And WeakMap — Frontend Architecture & Web Platform
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services
- Writable Streams: Drain Events & highWaterMark — Node.js Internals & Backend Services
- Backpressure Engineering: Handling Mismatched I/O — Node.js Internals & Backend Services
- Child Processes: spawn, execFile, fork & IPC — Node.js Internals & Backend Services
- Diagnostic Profiling: CPU Profiler & Heap Snapshots — Node.js Internals & Backend Services
- useEffect Lifecycle: Mount, Dependencies, And Cleanup Phases — React 19 & Modern Component Architecture
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture
- The React Compiler: Automated Memoization Under The Hood — React 19 & Modern Component Architecture
- Monolith Versus Services: The Honest Trade Offs — Scalable System Design & Distributed Architecture