Any ideas on a memory leak using $.ajax json call?

Any ideas on a memory leak using $.ajax json call?


Hi, I'm trying to chase down a memory leak in my application, it's a page that constantly refreshes data from a json query.  In particular the $.ajax call is causing problems. 


I've pruned it down to a basic page that gets a small amount of json data from an appengine service.  When it does 3000 json calls over about 15 minutes memory usage on ie goes from about 18MB to 105MB  (ie7 on windows xp).  Firefox seems to leak too but not as badly.


You can try it out at http://appden.appspot.com/zMockups/jsonMem.html the code is at http://appden.appspot.com/zMockups/jsonMem.js Here's the key bit:




  1. $(document).ready(function () {
  2.     // http://localhost:8087/zMockups/jsonMem.html
  3.     // http://appden.appspot.com/zMockups/jsonMem.html
  4.     setTimeout(function () {
  5.         var timeout = 400; 
  6.         if (numLiveRequests < 10) {
  7.             doJqueryJsonSimple('/jsonExample');
  8.             totalRequests++;
  9.             numLiveRequests++;
  10.             if (totalRequests < 3000) {
  11.                 setTimeout(arguments.callee, timeout);
  12.             }
  13.         } else {
  14.             setTimeout(arguments.callee, timeout);
  15.         }
  16.     },
  17.     0);
  18.     var logTimeout = 2000;
  19.     setTimeout(function () {
  20.         $('#show').html('total, num live - ' + totalRequests + ' ' + numLiveRequests);
  21.         setTimeout(arguments.callee, logTimeout);
  22.     },
  23.     100);
  24. });

  25. var handleJson = function (json) {
  26.     numLiveRequests--;
  27. };

  28. var doJqueryJsonSimple = function (url) {
  29.     $.ajax({
  30.         url: url,
  31.         data: {
  32.             "a": "a"
  33.         },
  34.         dataType: "json",
  35.         error: function (ajaxRequest, status, error) {
  36.             log('error:', ajaxRequest, status, error);
  37.         },
  38.         success: function (data, textStatus, XMLHttpRequest) {
  39.             handleJson(data);
  40.         }
  41.     });
  42. };


Is there anything I should be doing in the way of nulling out or deleting the json?  Or did I miss something else?


Also I was using the jsonp plugin elsewhere and decided to try to plug that in.  It actually does much better, maybe even not leaking at all.  That page is here: http://appden.appspot.com/zMockups/mockupJsonMem.html?jsonType=jsonp.jsonp&remote=false


And you can run a jQuery version of the same page here http://appden.appspot.com/zMockups/mockupJsonMem.html?jsonType=jQ.json&remote=false


I'm a little stumped, it sort of looks like the problem is in jQuery, but googling isn't finding anyone else with a similar issue.  Any ideas?


Thanks,

Josh