Garbage collection automatically reclaims memory occupied by objects that a JavaScript engine can no longer reach. It cannot know which objects you no longer need merely by intent; it looks for missing references or links. section 4.3
Web Components make the practical risk visible. Removing an element from the DOM does not automatically stop its timer or server polling. Use disconnectedCallback to clear timers and reset or null variables that link to other objects, giving garbage collection a better opportunity to reclaim them. section 4.3
Stop work when the element leaves the DOM
Store the interval handle, then clear it during disconnection: connectedCallback() { this.timer = setInterval(() => this.update(), 1000); } disconnectedCallback() { clearInterval(this.timer); } Without the cleanup callback, the component can continue updating and querying after removeChild removes it. section 4.3
Trace which objects remain linked inside a Web Component and which references can become collectible. section 4.3








