#1242 closed bug (fixed)
Unload event handlers may cause memory leaks in Internet Explorer
Reported by: | choan | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.1.3 |
Component: | event | Version: | 1.1.2 |
Keywords: | internet explorer, leaks | Cc: | |
Blocked by: | Blocking: |
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 (3)
Change History (4)
Changed 16 years ago by
Attachment: | unfixed-no-closure.png added |
---|
comment:1 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thanks choan! This is a great way to help avoid those pesky memory leaks. This patch is now applied in Rev [2010].
Memory grow without the fix