Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this a memory leak in JavaScript?
    primarykey
    data
    text
    <p>I was reading this article ( <a href="http://www.ibm.com/developerworks/web/library/wa-memleak/" rel="nofollow">http://www.ibm.com/developerworks/web/library/wa-memleak/</a> ) on IBM's website about memory leaks in JavaScript when I came across a memory leak that didn't quite look liked it leaked:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; 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 }; &lt;/script&gt; &lt;button id="element"&gt;Click Me&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I understood all the other leaks but this one stood out. It says there's a circular reference between the DOM and JavaScript object but I don't see it. </p> <p>Can anyone shed some light on this?</p> <p>EDIT: The link seems to have been taken down (I even refreshed the page I had up and it was down). Here's Google's cache (for as long as that lasts: <a href="http://webcache.googleusercontent.com/search?q=cache%3akLR-FJUeKv0J%3awww.ibm.com/developerworks/web/library/wa-memleak/%20memory%20management%20in%20javascript&amp;cd=1&amp;hl=en&amp;ct=clnk&amp;gl=us&amp;client=firefox-a" rel="nofollow">http://webcache.googleusercontent.com/search?q=cache:kLR-FJUeKv0J:www.ibm.com/developerworks/web/library/wa-memleak/+memory+management+in+javascript&amp;cd=1&amp;hl=en&amp;ct=clnk&amp;gl=us&amp;client=firefox-a</a> )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload