[jQuery] New filter :alternate + IE leaking
It doesn't matter if the code inside the event handler references a DOM
node, the closure itself already references it, whether the inner function
actually uses it or not. $(...).each() holds references to each matching DOM
node.
This turns out to be a case that my $.closure() patch fixes. I didn't submit
that patch for jQuery because we discovered there are some leaks it doesn't
fix. But it does fix this one.
Try this:
http://mg.to/test/agachi/fix.alternate.htm
and a copy of your original for comparison:
http://mg.to/test/agachi/leak.alternate.htm
The two copies of jQuery are in:
http://mg.to/test/agachi/fix.jquery.js
http://mg.to/test/agachi/leak.jquery.js
You can diff them to see the addition. It's the $.closure() function and a
one-line change in addEvent() to call it. I also commented out the unload
handler because it isn't needed.
I think memory leaks are the bane of a browser JavaScript developer. I'm
tracking down a different one right now that affects both Firefox and IE,
isn't caused by event handler closures, and is just a real pain in general!
:-)
-Mike