Hi Kelvin, I'm resurrecting this thread per your note about memory leaks in
the "date picker plugin bug fix" thread.

> $('div.popup-calendar', _openCal).remove();

That removes the node from the document tree, but references to the removed
node (and its children) are still left in the _openCal variable. That is
probably a major source of the leakage. I didn't think through all the
implications of this, or why chaining would work differently than not
chaining. Both .remove() and .empty() are documented to work this way. I
wasn't sure how you would remove the actual nodes from the jQuery object but
leave the others. Maybe John can weigh on on this.

Also, I think that when you remove DOM nodes that have event handlers
attached, IE is not smart enough to know that the memory can be reclaimed.
By using .empty() to remove individual elements before whacking the root
node, it's possible that some of the elements without events are being
reclaimed. There are a few events attached in elements below _openCal (like
closeLink) that might cause a problem.  I'd expect that at least a few of
them are left behind though, are you still seeing a small amount of memory
leakage despite your fix?


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kelvin Luck
Sent: Sunday, September 10, 2006 9:09 AM
To: jQuery Discussion.
Subject: [jQuery] datePicker plugin IE memory leak fixed

Hi,

I have just released an updated version of my date picker plugin:
http://kelvinluck.com/assets/jquery/datePicker/

Thanks to Sean McKenna who reported a memory leak in IE. This turned out to
be a pretty major one but relatively easy to fix and so I'd recommend anyone
using the date picker to upgrade ASAP...

I would like some advise on the cause of the problem and if there is a more
robust solution. Basically, when the calendar opens IE uses a bunch more
memory (~35MB on my system). When you switch months I was clearing the old
calendar from the DOM by doing this:

$('div.popup-calendar', _openCal).remove();

(basically calling remove on the div that contained it). This wasn't freeing
the memory in IE and another ~35MB or so was being used. And when you closed
the calendar and the pop up div was removed only the last ~35MB was being
freed up. As you can imagine, a recipe for disaster!

My solution was to call:

$('div.popup-calendar', _openCal).empty();

Before the remove command above. Now IE consistently uses ~35MB more memory
while the calendar is open and frees this when the calendar closes. Much
better.

I was wondering if it is expected behaviour to have to call empty before
remove when developing with jQuery or whether this should be done
internally?

One other problem I noticed is that if I chain the two calls (as I should be
able to):

$('div.popup-calendar', _openCal).empty().remove();

Now when the calendar opens it uses ~35MB more memory. When you switch
months for the first time it doubles this to ~70MB more memory. It stays
constant at this while you switch months and then frees the memory when you
close the calendar. It is interesting that the chained methods react
consistently differently to calling the methods one after the other - is
this expected or indicative of another bug?

Sorry for the long email but I'd appreciate it if anyone had any feedback on
these problems,

Cheers,

Kelvin :)


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to