All:
I am pretty new to Javascript memory management, currently reading:
https://www.ibm.com/developerworks/library/wa-memleak/wa-memleak-pdf.pdf
Inside this article, for Listing5, the explaination says:
In Listing 5 you see a closure in which a JavaScript object (obj) contains a reference to a DOM object (referenced by the id "element"). The DOM element, in turn, has a reference to the JavaScript obj. The resulting circular reference between the JavaScript object and the DOM object causes a memory leak.
could anyone give me some more detail about how this pattern gets circular reference built up and cause memory leak(a graph will be greatly appreciated)? Especially this part:
The DOM element, in turn, has a reference to the JavaScript obj.
document.write("Program to illustrate memory leak via closure");
window.onload = function outerFunction() {
var obj = document.getElementById("element");
obj.onclick = function innerFunction() {
alert("Hi! I will leak");
};
obj.bigString = new Array(1000).join(new Array(2000).join("XXXXX"));
// This is used to make the leak significant
};
<button id="element">Click Me</button>