Bug Tracker

Ticket #1242 (closed bug: fixed)

Opened 2 years ago

Last modified 9 months ago

Unload event handlers may cause memory leaks in Internet Explorer

Reported by: choan Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.1.3 Component: event
Version: 1.1.2 Keywords: internet explorer, leaks
Cc: Needs: Review

Description

As the unload event handlers are not removed by the event system, they may cause memory leaks in Internet Explorer.

* This leaks seams to appears only when a jQuery page is openened in a new window which is then closed. * The leak doesn't appear if the event handler unregisters itself. * It'd be nice to have the fix in core (Patch attached).

Steps to reproduce:

Create a page with the following code:

$(window).unload(function(){});

Navigate to this page with Internet Explorer 6. Open some new windows, watch the memory in use grow. Close all windows except the first one. Repeat some times. (Memory usage graphic attached.)

Fixes:

If we leave the work to be done by the developer:

// Use `one` instead of `bind` for unload event handlers
// the handler will be autounregistered
$(window).one("unload", function(){});
// Unbind the handler by itself
$(window).bind("unload", function(e) {
  $(this).unbind(e);
});
// In pre 1.1 versions
$(window).bind("unload", function(e) {
  $(this).unbind("unload", arguments.callee);
});

With the proposed fix, every bind("unload", f) would delegate in one("unload", f) so the programmer won't have to think about this leak.

Attachments

unfixed-no-closure.png (10.6 kB) - added by choan 2 years ago.
Memory grow without the fix
fixed-no-closure.png (11.5 kB) - added by choan 2 years ago.
Memory usage doesn't grow
patch-unload2one.txt (433 bytes) - added by choan 2 years ago.
Proposed patch

Change History

Changed 2 years ago by choan

Memory grow without the fix

Changed 2 years ago by choan

Memory usage doesn't grow

Changed 2 years ago by choan

Proposed patch

Changed 2 years ago by brandon

  • status changed from new to closed
  • resolution set to fixed

Thanks choan! This is a great way to help avoid those pesky memory leaks. This patch is now applied in Rev [2010].

Note: See TracTickets for help on using tickets.