[jQuery] event leak(mozilla) -- a quick fix...
JQuery rocks!
I have been playing with for a few days now and have discovered
a little leakage that occurs in Firefox.
I always have the "Leak Monitor" extension enabled during development
and it is quite annoying to get a leak notice every page reload. I
found the source to be from a DOM 2.0 event that is registered for
$.ready() if it looks like DOM 2.0 events are supported.
BTW: I get this leak every time I load a new page just about anywhere on
the JQuery site or any place that is using the JQery-based greybox, etc...
My quick fix is to just remove the event in $.ready() when it fires...
This seems ok, since the $.ready() func will always be registered anyway
-- I'm sure there is a better way...
Anyway - it would be great to see this fix (or something that
accomplishes the same thing) find its way into the official sources.
(an "onunload" event for "window" would be better and could be a great
place to do other "garbage collection" tasks for [still]registered event
handlers...).
Here's the quick-fix....
Original:
-------------------------------
$.ready = function() {
if ( $.$$timer ) {
clearInterval( $.$$timer );
$.$$timer = null;
for ( var i = 0; i < $.$$ready.length; i++ ) {
$.apply( document, $.$$ready[i] );
}
$.$$ready = null;
}
};
Fixed:
-----------------------
$.ready = function() {
if( document.addEventListener ) {
document.removeEventListener( "DOMContentLoaded", $.ready, null );
}
if ( $.$$timer ) {
clearInterval( $.$$timer );
$.$$timer = null;
for ( var i = 0; i < $.$$ready.length; i++ ) {
$.apply( document, $.$$ready[i] );
}
$.$$ready = null;
}
};
- B
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/