Releasing memory used by untied DOM nodes in Javascript

As part of my application, I am compiling a set of small Dom nodes that are not displayed at the same time. I store them in an internal array. The user can call them to display, in which case I return them to the div that is used to display them. This is all good and good. But when it is time to replace everything with new ones, I want to destroy the old ones (actually free them). Otherwise, memory usage may increase exponentially. How to make js browser engine do this? Is it just setting each of the elements in my array of Dom nodes to zero? Is there anything else I should do? Or maybe I don’t have to worry about this at all?

+5
source share
2 answers

If you set each item to null, they will automatically collect garbage.

+5
source

Yes, setting the elements to zero should be fine ... Except that with Internet Explorer you need to take care of some implementation details: handling circular references is dodgy. See http://msdn.microsoft.com/en-us/library/bb250448.aspx

Circular links. When reciprocal links are counted between the Internet Explorer COM browser infrastructure and any scripting engine, objects may leak memory

Therefore, in some cases, you need to break circular links.

+5
source

All Articles