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.