title: Simple jQuery Ajax call leaks memory in Internet Explorer
body: <p>I created a web page that makes an Ajax call every second. In Internet Explorer 7, it leaks memory badly (20 MB in about 15 minutes).</p>
  
  <p>The program is very simple. It just runs a JavaScript function that makes an Ajax call. The server returns an empty string, and the JavaScript code does nothing with it. I use <code>setTimeout</code> to run the function every second, and I'm using <a href="http://sourceforge.net/projects/ieleak/" rel="noreferrer">Drip</a> to watch the thing.</p>
  
  <p>Here is the source:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
        google.load('jquery', '1.4.2');
        google.load('jqueryui', '1.7.2');
      &lt;/script&gt;
      &lt;script type="text/javascript"&gt;
        setTimeout('testJunk()',1000);
        function testJunk() {
          $.ajax({ url: 'http://xxxxxxxxxxxxxx/test', // The url returns an empty string
                   dataType: 'html',
                   success: function(data){}
                 });
          setTimeout('testJunk()',1000)
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      Why is memory usage going up?
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>How to plug this leak? I have a real application that updates a large table this way, but left unattended it will eat up gigabytes of memory.</p>
  
  <p><strong>Edit</strong>: okay, so after some good suggestions, I modified the code to:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
        google.load('jquery', '1.4.2');
        google.load('jqueryui', '1.7.2');
      &lt;/script&gt;
      &lt;script type="text/javascript"&gt;
        setTimeout(testJunk,1000);
        function testJunk() {
          $.ajax({ url: 'http://xxxxxxxxxxxxxx/test', // The url returns an empty string
                   dataType: 'html',
                   success: function(data){setTimeout(testJunk,1000)}
                 });
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      Why is memory usage going up?
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>It didn't seem to make any difference, though. I'm not doing anything with the DOM, and if I comment out the Ajax call, the memory leak stops. So it looks like the leak is entirely in the Ajax call. Does jQuery Ajax inherently create some sort of circular reference, and if so, how can I free it? By the way, it doesn't leak in Firefox.</p>
  
  <p>Someone suggested running the test in another VM and see if the results are the same. Rather than setting up another VM, I found a laptop that was running XP Home with Internet Explorer 8. It exhibits the same problem.</p>
  
  <p>I tried some older versions of jQuery and got better results, but the problem didn't go away entirely until I abandoned Ajax in jQuery and went with more traditional (and ugly) Ajax.</p>