Skip to main content

Bug Tracker

Side navigation

#6421 closed bug (invalid)

Opened April 12, 2010 03:03AM UTC

Closed October 02, 2010 07:08PM UTC

Last modified March 14, 2012 01:28AM UTC

Memory leak in IE6/7

Reported by: morris Owned by:
Priority: undecided Milestone: 1.4.3
Component: event Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

The line

window.attachEvent( "onload", jQuery.ready );

can leak a window object (which happens to be a big object). Detected using IEJSLeaksDetector.

I cannot seem to reproduce this in a small test file, and showing you the leak on my test system is not practical.

However there is a very simple fix, simply add the matching detachEvent call into the cleanup code i.e.:

if ( window.attachEvent && !window.addEventListener ) {
	window.attachEvent("onunload", function() {
		for ( var id in jQuery.cache ) {
			if ( jQuery.cache[ id ].handle ) {
				// Try/Catch is to handle iframes being unloaded, see #4280
				try {
					jQuery.event.remove( jQuery.cache[ id ].handle.elem );
				} catch(e) {}
		// The following line added by me to fix leak!
		window.detachEvent( "onload", jQuery.ready );

The cleanup code exists to deregister all event handlers, but it also needs to deregister any for which attachEvent was called manually in the jQuery base code (Ironically however, it seems you don't have to deregister the window.attachEvent("onunload" ...); event within the function above!)

I am presuming leak is also in IE7 (not tested, but fairly certain!).

Attachments (0)
Change History (2)

Changed June 12, 2010 02:39AM UTC by dmethvin comment:1

component: unfiledevent

Changed October 02, 2010 07:08PM UTC by addyosmani comment:2

priority: → undecided
resolution: → invalid
status: newclosed

Please re-submit this ticket with either a test case or steps for us to reproduce the code running in your local setup so that we can investigate further.