John I am not arguing, I am just exposing something I did not think about
before.

jQuery would like to avoid leaks but apparently leaks are intrinsic because
the instance is not updated, there are a lot of operation that could be
performed in nodes that are not used anymore, and the chaining practice
brings these nodes everywhere.

Another example, I always preferred to cache variables ... $j = $("my
search") rather than use $("my search") everywhere.
I do this to avoid to "stress" Sizzle and the browser but right now I am
starting to think that it is the only way to avoid leaks, hoping the browser
will discard precedent created instances asap.

What are your thoughts about this?

On Tue, Aug 18, 2009 at 3:34 PM, John Resig <jere...@gmail.com> wrote:

> Well, if you're arguing that you might as well argue that .remove() should
> return an empty set - since the elements are no longer in the document.
>
> --John
>
>
>
> On Tue, Aug 18, 2009 at 10:30 AM, Andrea Giammarchi <
> andrea.giammar...@gmail.com> wrote:
>
>> Actually, me and phiggins were looking at TaskSpeed bench and he spotted
>> an error in my Pure DOM which was basically the reason we realized every
>> single test there was wrong.
>>
>> let's do an example. My document has 3 divs:
>>
>> '<div><div></div></div><div></div>'
>>
>> one is nested ... now I do this:
>>
>> $("div").html("leak?").length; // which is 3
>>
>> I am not sure if all libraries are managing the case in the same way but I
>> would not leave that div wrapped in that variable.
>>
>> If jQuery object related search is saved, it could be useful to re-search
>> it after each operation otherwise problems like this will be truly common
>> and leaks more probable than pure DOM manipulation.
>>
>> That test for example is now:
>>
>> var div = document.getElementsByTagName("div"), i = 0;
>> while(div[i])
>>     div[i++].innerHTML = "leak?";
>> return i;
>>
>> because getElementsByTagName is live and I do not want to trap anything.
>>
>> Makes sense?
>>
>>
>>
>>
>> On Tue, Aug 18, 2009 at 1:40 PM, John Resig <jere...@gmail.com> wrote:
>>
>>> Well, you could just manipulate this[0], this[1], etc. directly - but
>>> it's strongly preferred that you return the new result with pushStack (as
>>> you've done) since that conforms with the typical way of constructing jQuery
>>> methods and plugins.
>>>
>>> --John
>>>
>>>
>>>
>>> On Mon, Aug 17, 2009 at 3:46 PM, jeanph01 <jeanp...@gmail.com> wrote:
>>>
>>>>
>>>> Hi!
>>>>
>>>> I'm creating a jquery plugin that alter an object to remove duplicates
>>>> in it. My problem is that a variable that access the old selector
>>>> result does not contain the same elements that it would have contained
>>>> if it would have been executed after the duplicates removal.
>>>> To illustrate :
>>>>
>>>> var v = $('div);   // 150 objects
>>>> v.removeDuplicate();   // remove 10 duplicates
>>>> // here v still point to 150 objects
>>>>
>>>>
>>>>
>>>> Here is my plugin :
>>>>
>>>> jQuery.fn.__sort = function() {
>>>>    return this.pushStack([].sort.apply(this, arguments), []);
>>>> };
>>>>
>>>> jQuery.fn.sort = function(func) {
>>>>    function internalSort(a,b){
>>>>        var compA = $(a).text();
>>>>        var compB = $(b).text();
>>>>        return (compA <> compB) ? 1 : 0;
>>>>    }
>>>>    if (!$.isFunction(func)) {
>>>>        func = internalSort;
>>>>    }
>>>>    return this.__sort(func);
>>>> };
>>>>
>>>> jQuery.fn.removeDuplicate = function() {
>>>>    var that = $(this).sort();
>>>>
>>>>    $(this).each(function() {
>>>>        var pos = that.index($(this));
>>>>        var next = that.eq(pos+1);
>>>>        var eq = (next.text() === $(this).text());
>>>>
>>>>        if (eq) { next.remove();}
>>>>    });
>>>>
>>>>    // enable chaining, updating selector
>>>>    return $($(this).selector);
>>>> };
>>>>
>>>>
>>>> The only solution I found is to return $(this) with an updated
>>>> selector. But I would have had to remember to update the content of my
>>>> variable before calling the plugin.
>>>> ex:
>>>> v = v.removeDuplicates();
>>>>
>>>> Can I update $(this) from within removeDuplicate() ??
>>>>
>>>> Thank you
>>>>
>>>> note: I posted this on the jQuery Plugins discussion put it seems
>>>> dead, or full of spam.
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to