Minimal SvelteKit app to reproduce accumulation of detached DOM nodes after mount/destroy cycles when the compiled template holds multiple DOM references (wrapper + <video> + controls) in shared closure scopes.
npm install
npm run devOpen the app, click “Remount 40×” several times (or “Remount once” repeatedly).
- Open Memory → Heap snapshot → take snapshot A (baseline).
- Click Remount 40× a few times (e.g. 5× = 200 teardowns).
- Optionally run
gc()in the console (Chrome must be started with--js-flags="--expose-gc"). - Take snapshot B.
- In snapshot B, filter by Detached and search for
HTMLVideoElement,HTMLDivElement, ordata-leak-repro.
Chrome describes the underlying DOM retention pattern: a JS reference to any node in a detached subtree keeps the entire subtree alive via parentNode / child links until that reference is dropped.
Clearing video.src / load() from app onDestroy did not fix large detached counts in a real app; breaking parent–child links after remove() in Svelte’s remove_effect_dom (runtime) did (~99% reduction in detached delta in that scenario). See the GitHub issue for details.