Bug Tracker

Ticket #6421 (closed bug: invalid)

Opened 4 years ago

Last modified 3 years ago

Memory leak in IE6/7

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

Description

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!).

Change History

comment:1 Changed 4 years ago by dmethvin

  • Component changed from unfiled to event

comment:2 Changed 4 years ago by addyosmani

  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to invalid

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.

Note: See TracTickets for help on using tickets.