atom feed22 messages in com.googlegroups.jquery-en[jQuery] Memory leaks forever
FromSent OnAttachments
Franck MarciaMar 25, 2006 7:13 am 
Dave MethvinMar 25, 2006 8:55 am 
Franck MarciaMar 25, 2006 9:08 am 
John ResigMar 25, 2006 9:15 am 
Dave MethvinMar 25, 2006 10:07 am 
Michael GearyMar 25, 2006 10:07 am 
Franck MarciaMar 25, 2006 10:39 am 
Michael GearyMar 25, 2006 10:56 am 
Dave MethvinMar 25, 2006 11:05 am 
Franck MarciaMar 25, 2006 1:45 pm 
Michael GearyMar 25, 2006 2:19 pm 
Franck MarciaMar 25, 2006 5:16 pm 
Dave MethvinMar 26, 2006 9:02 am 
Michael GearyMar 26, 2006 1:24 pm 
Franck MarciaMar 28, 2006 2:25 am 
Dave MethvinMar 28, 2006 5:45 am 
John ResigMar 28, 2006 7:30 am 
Franck MarciaMar 28, 2006 8:26 am 
jqu...@vikas.mailshell.comMar 28, 2006 8:57 am 
John ResigMar 28, 2006 9:03 am 
Michael GearyMar 28, 2006 9:14 am 
jqu...@vikas.mailshell.comMar 28, 2006 9:24 am 
Subject:[jQuery] Memory leaks forever
From:Dave Methvin (
Date:Mar 25, 2006 11:05:38 am

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 at [mailto:discuss-bounces at] 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:

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);