Concepts
Detached node retention
Removing a node disconnects it from the document; a separate strong reference can keep it reachable. Removing the application reference is not a garbage collection assertion.
Formal Syntax & Structure
javascript syntaxjavascript
element.remove(); retained.delete(element)Working Example
Example Snippetjavascript
(async () => {const el=document.createElement("div");document.body.append(el);const retained=new Set([el]);el.remove();console.log(el.isConnected,retained.has(el));retained.delete(el);console.log(retained.size);})()