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 (dave@gmail.com)
Date:Mar 25, 2006 10:07:13 am
List:com.googlegroups.jquery-en

it doesn't seem like it would help Franck's code as he's not removing any elements

It looked like Franck had only showed a part of his code so I thought there must have been some places where he was removing elements. If not then the leak would be occurring when the user reloads or navigates away from the page.

should some sort of auto-clean-up be run when the page is unloaded, for IE?

Seems like that's the only way to solve the leaks according to Doug's page.

I do keep a reference to all events that were added using bind/addEvent, so that is a possibility.

That might be faster than doing what Doug did, looking through all properties of the whole DOM subtree to see if there were any functions attached.

-----Original Message----- From: discuss-bounces at jquery.com [mailto:discuss-bounces at jquery.com] On Behalf Of John Resig Sent: Saturday, March 25, 2006 12:15 PM To: jQuery Discussion. Subject: Re: [jQuery] Memory leaks forever

Dave -

Doug's code is really interesting and it seems like it'd be simple enough to integrate into the .html() .empty() and .remove() functions.

But I'm confused, it doesn't seem like it would help Franck's code as he's not removing any elements - should some sort of auto-clean-up be run when the page is unloaded, for IE? I do keep a reference to all events that were added using bind/addEvent, so that is a possibility.

Let me know.

On 3/25/06, Dave Methvin <dave.methvin at gmail.com> wrote:

Is it because of the code structure? Because I'm using static functions? Did I misuse jQuery?

This looks like the memory leak that occurs when you remove an element but still have event functions bound to it. Mike Geary pointed to a paper on this in an earlier thread:

http://jquery.com/discuss/2006-March/000375/

However, I am wondering about the goodness of that paper because the code examples look weird. I thought that document.createElement just took a tag name and they are passing it HTML?

Doug Crockford has some code that demonstrates and fixes the problem:

http://crockford.com/javascript/memory/leak.html

It might be fixed if JQuery methods null out events whenever they are removing DOM nodes, such as in empty() or remove(). Otherwise you'd need to unbind() events manually any time you're removing nodes. It also has to be done whenever you leave or reload a page (by binding to the unload event).