JavaScript·Intermediate·Coding·1 min read
What is a detached DOM tree?
Short interview answer
It is a DOM subtree removed from the document but still reachable from JavaScript, perhaps through a listener, closure, cache, or framework reference. Being detached is not itself a leak; continued unintended reachability is.
Example
const cache = [];function render() { const el = document.createElement('div'); cache.push(el); // keeps every `el` alive forever document.body.append(el); el.remove(); // detached from the document, still in `cache`}Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.