detached DOM tree
DOM nodes that have been removed from the page but are still kept in memory because some JavaScript still references them.
In more detail
Removing an element does not free it if a variable, a listener, an observer or a cache still points to it, and one reference keeps its whole subtree alive. Heap snapshots in developer tools list detached nodes so you can find the culprit.
Related terms
- memory leak — Memory that a program keeps holding although it no longer needs it, so usage grows until the program slows down or crashes.
- 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.
Taught in
- MutationObserver: Reactive DOM Watching Without Polling — Frontend Architecture & Web Platform
- Memory Management: Garbage Collection, Memory Leaks And WeakMap — Frontend Architecture & Web Platform