Bug Tracker

Opened 15 years ago

Closed 15 years ago

#991 closed bug (fixed)

Ajax leaking in IE6

Reported by: choan Owned by:
Priority: major Milestone: 1.1.2
Component: ajax Version: 1.1.1
Keywords: leaks Cc:
Blocked by: Blocking:

Description

We (my team and our clients) are experimenting serious memory leaks while using the Ajax methods (as expected, just in IE6).

Demo page (runs jQuery 1.1.1): http://blog.scriptia.net/temp/jquery-ajax-leaks/ajax-leaks.html. Leaks seriously.

After some investigation, I've found http://alex.dojotoolkit.org/?p=528, a post by Alex Russell where he writes:

"As with DOM event handlers, IE gets easily confused about what it can and cannot clean up when you make XMLHTTP requests. The naive way of listening for the "finished" state in an asynchronous request is to attach a function to the XMLHTTP object's onreadystatechange slot and determine inside the handler if the desired state has been reached. The problem though is the same as with DOM event handlers; since the XMLHTTP object in IE is an ActiveX control, IEs reference counting mechanism goes walkabout when presented with an event handler that is assigned from the JavaScript context. The contexts (closures) referenced by the event handler get leaked. Oops.

After much testing, we figured out a pattern that prevents this kind of leakage. Instead of attaching a method to be called back to, Dojo's IO system starts a timer to watch for state changes on in-flight network requests. When a change is detected, we dispatch the correct event handler from outside the XMLHTTP object's event system. Since we never set a closure reference between the ActiveX object and the JavaScript context, we never leak it. Of course, once there are no more operations "in the air", we cancel the timer that watches for state changes to prevent further resource usage."

So, I've applied his method to jQuery. No leaks. See http://blog.scriptia.net/temp/jquery-ajax-leaks/ajax-fixed.html

I'm attaching a patch which:

  1. Uses a timer instead of onreadystatechange
  1. Nullifies both xml and xml2

Hope this helps in resolving the issue.

Attachments (1)

out.diff (958 bytes) - added by choan 15 years ago.

Download all attachments as: .zip

Change History (2)

Changed 15 years ago by choan

Attachment: out.diff added

comment:1 Changed 15 years ago by joern

Resolution: fixed
Status: newclosed

Fixed in revision [1399]. However, to enable synchronous calls, I can't clear the xml refernce inside the handler. That means, in the worst case, that memory leaks still occur for synchronous calls. One more reason to avoid them.

Note: See TracTickets for help on using tickets.