Browser troubleshooting

Avoid retaining removed DOM nodes

Removing a node from the document does not destroy JavaScript references to it. A detached node can remain alive if application state, a listener closure, or developer tools still retain it.

Worked example

Browser console example · use a disposable page on your own site

let panel = document.createElement("section");
panel.textContent = "Temporary panel";
document.body.append(panel);
console.log(panel.isConnected);
panel.remove();
console.log(panel.isConnected);
panel = null;

How it works

IsConnected reports whether the node belongs to a document-connected tree. The second result is false, but the variable still references the node until the final assignment. Real cleanup should release relevant application references and listeners when a component is no longer needed.

Limits and mistakes

A detached node is not inherently a leak; keeping an offscreen template deliberately may be valid. The issue is unintended retention over repeated operations. Inspect retaining paths before removing useful caches or changing component behavior.

Check the result

Expect true then false. Repeat the real panel lifecycle and look for nodes retained once per cycle. Avoid logging large DOM objects while measuring, since the console may keep references.

Sources

Reference documentation for the behavior used in this guide: