const elements = { button: document.getElementById('button'), image: document.getElementById('image'), text: document.getElementById('text') }; const doStuff = () => { image.src = 'http://some.url/image'; button.click(); console.log(text.innerHTML); // Much more logic } const removeButton = () => { // The button is a direct child of body. document.body.removeChild(document.getElementById('button')); // At this point, we still have a reference to #button in the global // elements dictionary. In other words, the button element is still in // memory and cannot be collected by the GC. }