Isn't it sufficient to simply special-case the empty namespace
invocation similar to jQuery.event.handle()?

I.e. in jQuery.event.remove():

    jQuery.each(types.split(/\s+/), function(index, type){
    [...snip...]

    var all = !namespaces.length; // <<=== NEW!
    var namespace = RegExp("(^|\\.)" + namespaces.slice().sort().join
(".*\\.") + "(\\.|$)");

    [...snip...]

    if (all || namespace.test(events[type][handle].type) ) // <<===
ADD CHECK AGAINST "all"
        delete events[type][handle];

-Dave

On Apr 27, 10:06 pm, Michael Park <[email protected]> wrote:
> Here's my stab at a fix that cleans up namespaced-event-handlers in in
> the jQuery.cache object on 'unload' event
> (jquery-1.3.2-namespaced-events-leak-fix.patch).
>
> To validate my changes, I alert-ed out the contents of jQuery.cache
> (jquery-1.3.2-unload-debug-out.patch).
>
> How to test:
> ------------------
> # save a backup copy
> cp jquery-1.3.2.js jquery-1.3.2.js.bak
>
> # apply patch for namespaced-events-leak fix
> patch -p0 jquery-1.3.2.js <jquery-1.3.2-namespaced-events-leak-fix.patch
>
> # apply patch for debugging output for the 'unload' event-handler
> patch -p0 jquery-1.3.2.js <jquery-1.3.2-unload-debug-out.patch
>
> # test it out with some sample HTML like so (load it, and hit reload
> to trigger the 'unload' event):
> <html>
> <head>
> <script type="text/javascript" src="/js/jquery-1.3.2.js"></script>
> <script>
> $(document).ready(
>   function () {
>     $('#b1').bind('click.foo', function() { alert('b1'); });
>     $('#b1').bind('click.bar', function() { alert('b1'); });
>   }
> );
>
> </script>
> </head>
> <body>
> <button id="b1">test</button>
> </body>
> </html>
>
> # when satisfied, rollback the debug output patch
> patch -p0 -R jquery-1.3.2.js <jquery-1.3.2-unload-debug-out.patch
>
> ------------------
>
> Questions, comments, or if there's some other preferred way of
> submitting a fix, please let me know. Thanks.
>
> --Mike
>
> On Sat, Apr 25, 2009 at 1:09 PM, Mike Park <[email protected]> wrote:
> > new thread, as requested (original message below):
> > -------
>
> > There is definitely a problem with the way jQuery (I'm using 1.3.2)
> > handles cleaning up namespaced events (I'm tracing the 'unload' event
> > codepath). The problem from what I can tell seems to be in
> > jQuery.event.remove:
>
> > 2540         // Handle multiple events seperated by a space
> > 2541         // jQuery(...).unbind("mouseover mouseout", fn);
> > 2542         jQuery.each(types.split(/\s+/), function(index, type){
> > 2543           // Namespaced event handlers
> > 2544           var namespaces = type.split(".");
> > 2545           type = namespaces.shift();
> > 2546           var namespace = RegExp("(^|\\.)" + namespaces.slice
> > ().sort().join(".*\\.") +      "(\\.|$)");
>
> > ...during the 'unload' event-handler codepath, this code snippet here
> > is expecting the passed in 'types' argument to contain the namespaced
> > event-identifier (ex. 'click.foo'), but instead it is getting the
> > common event-identifier instead (ex. 'click').
>
> > You can firebug-trace this yourselves with the simple examples I put
> > up here:
> >  http://emparq.com/ex/ex-good.html
> >  http://emparq.com/ex/ex-bad.html
>
> > ...you'll notice the only difference between these two examples is
> > that one binds 'click.foo' and the other binds 'click'. In the bad
> > example, hitting reload constantly will see the process memory useage
> > go up (in essense, a leak) due to 'jQuery.event.remove' not properly
> > cleaning up the namespaced 'click.foo' event), while the good example
> > will not suffer the same results.
>
> > I'm still new-ish to jQuery and I'm not ready to hazard a solution
> > just yet, but I'm guessing something either needs to be done with the
> > way 'jQuery.event.remove' handles the value of the 'types' argument,
> > or this code here:
>
> > 2531         for ( var type in events )
> > 2532           this.remove( elem, type + (types || "") );
>
> > ...needs to be modified to properly put those namespaced suffixes back
> > into the second argument. I'm not familiar enough with all of the use-
> > cases that this function handles, so I don't know which is the best
> > approach.
>
> > Can anyone else shed some light on this subject?
>
> > --Mike
>
>
>
>  jquery-1.3.2-namespaced-events-leak-fix.patch
> 2KViewDownload
>
>  jquery-1.3.2-unload-debug-out.patch
> 1KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to