[jQuery] Memory leaks forever
Mike, so the goal of $.closure is to put all event handlers in the window
object so that they will be properly cleaned up when the page is unloaded?
It seems like that wouldn't help the leaks with elements removed while the
page is running, unless empty() and the others also remove events.
I have to admit, this stuff about leaks is seriously confusing me. There
seems to be a lot of bad or ambiguous information about the IE memory leak
problem. Doug Crockford says that Microsoft's document generally blaming
closures is wrong--although closures *can* cause leaks--and the Microsoft
article you mentioned earlier seems to make non-standard (non-sensical?) use
of document.createElement. I'm not clear on if and when these memory leaks
resolve themselves, for example whether they go away when you navigate off a
page. From some of the info I thought they persisted across pages and/or
reloads, but I tried writing the simplest possible sample code (not JQuery
but raw DOM calls with attached events) and I don't see any repeatable
leakage pattern that way.
For example, doesn't jquery-dom.js have the potential to leak as well? The
Insertion Order Leak that Microsoft describes says that nodes should be
inserted from the top down rather than the bottom up. If you were to attach
an event handler in a $.DIV call and nest that in another $.DIV call then
that seems like it would leak.
-----Original Message-----
From: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com] On
Behalf Of Michael Geary
Sent: Saturday, March 25, 2006 1:08 PM
To: 'jQuery Discussion.'
Subject: Re: [jQuery] Memory leaks forever
I'm not sure what is causing this leak, unless all this code were nested
inside another function, in which case it would be the closure circular
reference leak.
I would be curious to know if my $.closure patch fixes it. Would you want to
try it and let me know? I've been meaning to post something about this, but
in the meantime here is the code:
http://mg.to/jquery-code/closure.js
It's not a .patch file, just edit the code into a test copy of jQuery.
You'll need to add the $.closure() function itself, and then in addEvent()
there is a one-line change. This line:
handlers[handler.$$guid] = handler;
needs to be changed to:
handlers[handler.$$guid] = $.closure(handler);
-Mike
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/