If I have a map containing the ids of DOM elements and I want to de-reference an entry in the map, so the corresponding element can be picked up by garbage collector, what are the steps I should go through to make sure there is no memory leak? Should I delete or = null on the map entry? What do I need to do about the element itself?
If I have a map containing the id s of DOM elements and I
Share
(I assume by “map” you mean “object”.)
To permanently remove a property and value from an object, use
delete. Usingnullwill have the effect of clearing the value, but retaining the property.Both will allow the value to be garbage collected.
But to what you’re trying to accomplish, if the map only has reference to an ID string, it will have no impact on the element itself. You need to drop all references to the element (in DOM and JavaScript) to ensure the element is garbage collected.