Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#6421 closed bug (invalid)

Memory leak in IE6/7

Reported by: morris Owned by:
Priority: undecided Milestone: 1.4.3
Component: event Version: 1.4.2
Keywords: Cc: [email protected]
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!).

Change History (2)

comment:1 Changed 13 years ago by dmethvin

Component: unfiledevent

comment:2 Changed 12 years ago by addyosmani

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.

Note: See TracTickets for help on using tickets.