Any modern browser garbage collector can handle circular links. Your object will be garbage collected if you both lose all references to the object and delete all HTML nodes from the DOM (while in the DOM, the browser sees a link to your object and does not allow it to collect garbage). However, be careful with event handlers; they can also perform checks if you also do not delete them.
I heard that some older versions of IE have issues with circular references. For a more detailed explanation: Exact JavaScript Explanation β DOM Round Question
From this answer: jQuery.data () makes the thing more reliable, since older versions of IE had a certain problem with the properties that were added to the DOM element, and did not handle circular references that correctly included data in these properties, and thus things would not free when they should eat (leak) .. data () works around this, using only one added property in the DOM element, which is safe, not leak. This line is the key to the javascript object, which can contain all the properties that you want to associate with the DOM element. Since these properties are stored in simple javascript, where browsers do not have circular support errors, this method does not cause leaks.
You might want to learn D3.js, it does something similar to what you want. It associates data with DOM elements and provides an easy way to generate visualizations: http://d3js.org/
Using D3, you can bind an array of numbers to an array of round SVG tags and make each circle have a radius based on the amount of array associated with it.
EDIT: I forgot to mention that if you use $ .remove (), event handlers are also deleted. But if you have, for example, an event handler that is inside the closure that also has a link to your (remote) HTML node, it will not collect garbage. This is usually not a big problem, because when it goes beyond the DOM, it will not consume too many resources, and as far as I know, it is impossible to restore all of these closing links.
source share