Ok, thanks for the explanation, we'll look into this for 1.3.
What about:
if (this.parentNode)
this.parentNode.removeChild(this);
this.outerHTML = '';
On Wed, Dec 3, 2008 at 7:05 PM, Chris Robinson <[EMAIL PROTECTED]> wrote:
>
> Both "leak" but not in the classic sense. IE uses 2 separate instances of
> the DOM. One is DOM in javascript, One is the DOM of the HTML that's
> rendered in the browser. This leak we are seeing is not orphaned tags
> (Which is what programs like sieve keep track of). The leak is javascript
> DOM memory that's being used but not reclaimed once the DOM elements are
> removed. Reason being, in certain cases IE will crash if a code block tries
> to reference DOM elements that no longer exists. In general using
> removeChild in IE causes the browser to do a poor job identifying what
> references can and cannot be garbage collected. These inner/outer HTML
> methods seem to force IE's hand into doing a better (although not great) job
> of cleaning up.
>
> After running the tests at 2000 iterations it seems as though the outer
> method is just about as effcient as cleaning up as the innerHTML method.
>
> Essentially it comes down to changing the remove method to be the following:
>
> remove: function( selector ) {
> if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
> // Prevent memory leaks
> jQuery( "*", this ).add(this).each(function(){
> jQuery.event.remove(this);
> jQuery.removeData(this);
> });
> if (this.parentNode) {
> if (jQuery.browser.msie) {
> this.outerHTML = '';
> }
> else {
> this.parentNode.removeChild(this);
> }
> }
>
> }
> }
>
> the "evalScript" and "clean" methods also use removeChild under the hood but
> im not so sure they get used often enough to warrent a change.
>
> -Chris
>
>
> On Wed, Dec 3, 2008 at 8:22 AM, Ariel Flesler <[EMAIL PROTECTED]> wrote:
>>
>> So... let me get this right, both leak but innerHTML leaks less ?
>>
>> On Wed, Dec 3, 2008 at 2:45 AM, Chris Robinson <[EMAIL PROTECTED]> wrote:
>> >
>> > After a good deal of testing at 250 test runs it seems that the
>> > innerHTML
>> > "garbage bin" and outerHTML methods are almost identical when it comes
>> > to
>> > memory usage. outerHTML uses a VERY small amount more (around 36k). I
>> > am
>> > going to rerun the test at 2000 iterations to see if it makes a
>> > difference.
>> >
>> > Again, sorry for the delay, work is very hectic these days. I should be
>> > able to report back tomorrow during the day (fingers crossed).
>> >
>> >
>> > On Mon, Dec 1, 2008 at 3:26 PM, Andrea Giammarchi
>> > <[EMAIL PROTECTED]> wrote:
>> >>
>> >> Just as extra info, it seems that innerHTML with IE does a good work,
>> >> it
>> >> is like minimizing the window and maximizing it back. The problem is
>> >> that it
>> >> is not usable to force the CollectGarbage (that does not do its work as
>> >> expected to me ...) ... does anybody else has bad experience with IE
>> >> and
>> >> ExtJS over jQuery? :D
>> >>
>> >> On Thu, Nov 27, 2008 at 7:12 PM, Andrea Giammarchi
>> >> <[EMAIL PROTECTED]> wrote:
>> >>>
>> >>> Ariel I did a quick test with I don't remember which document and I
>> >>> received an error.
>> >>> Unfortunately I had no time to investigate but I have exactly the same
>> >>> problem, "empty does not empty" at all.
>> >>>
>> >>> If the trick with outerHTML works I'll try tomorrow in my application
>> >>> and
>> >>> I'll tell you.
>> >>>
>> >>> Regards
>> >>>
>> >>> On Thu, Nov 27, 2008 at 1:39 PM, Ariel Flesler <[EMAIL PROTECTED]>
>> >>> wrote:
>> >>>>
>> >>>> So how do you know some cause errors if you haven't tested yet ?
>> >>>>
>> >>>> On Thu, Nov 27, 2008 at 9:47 AM, Andrea Giammarchi
>> >>>> <[EMAIL PROTECTED]> wrote:
>> >>>> > I guess textNodes, html itself and probably iframes.
>> >>>> > I'll tell you as soon as I can test stuff :-)
>> >>>> >
>> >>>> > On Wed, Nov 26, 2008 at 1:21 PM, Ariel Flesler <[EMAIL PROTECTED]>
>> >>>> > wrote:
>> >>>> >>
>> >>>> >> Which nodes generate an error ?
>> >>>> >>
>> >>>> >> On Wed, Nov 26, 2008 at 5:53 AM, Andrea Giammarchi
>> >>>> >> <[EMAIL PROTECTED]> wrote:
>> >>>> >> > Hi Ariel, is this what you would apply for each nested node in
>> >>>> >> > case
>> >>>> >> > of
>> >>>> >> > $.empty() ?
>> >>>> >> >
>> >>>> >> > The only problem I can see is with nodes that generate an error
>> >>>> >> > if
>> >>>> >> > outerHTML
>> >>>> >> > property is assigned and a try catch could decrease execution
>> >>>> >> > speed.
>> >>>> >> >
>> >>>> >> > Any ideas?
>> >>>> >> >
>> >>>> >> > Regards
>> >>>> >> >
>> >>>> >> > On Tue, Nov 25, 2008 at 11:30 PM, Ariel Flesler
>> >>>> >> > <[EMAIL PROTECTED]>
>> >>>> >> > wrote:
>> >>>> >> >>
>> >>>> >> >> Well... I concluded a nicer solution and asked you to try it.
>> >>>> >> >> But you never replied...
>> >>>> >> >>
>> >>>> >> >> http://dev.jquery.com/ticket/3553
>> >>>> >> >>
>> >>>> >> >> if (this.parentNode)
>> >>>> >> >> this.parentNode.removeChild( this );
>> >>>> >> >> if (jQuery.browser.msie)
>> >>>> >> >> this.outerHTML = "";
>> >>>> >> >>
>> >>>> >> >> --
>> >>>> >> >> Ariel Flesler
>> >>>> >> >> http://flesler.blogspot.com/
>> >>>> >> >>
>> >>>> >> >> On Nov 25, 3:28 pm, "Chris Robinson" <[EMAIL PROTECTED]>
>> >>>> >> >> wrote:
>> >>>> >> >> > Hey Nick,
>> >>>> >> >> >
>> >>>> >> >> > this was never completely resolved. The edited jQuery source
>> >>>> >> >> > I
>> >>>> >> >> > was
>> >>>> >> >> > playing
>> >>>> >> >> > around with is
>> >>>> >> >> >
>> >>>> >> >> >
>> >>>> >> >> >
>> >>>> >> >> > here:http://www.outsidethediv.com/memory-leak-test/js/jquery-1.2.6-updated.js
>> >>>> >> >> >
>> >>>> >> >> > You can try swapping your jquery include with it and see if
>> >>>> >> >> > that
>> >>>> >> >> > helps
>> >>>> >> >> > at
>> >>>> >> >> > all. It seemed to help out a good deal in my case but was
>> >>>> >> >> > rather
>> >>>> >> >> > inconclusive in smaller stripped down tests.
>> >>>> >> >> >
>> >>>> >> >> > On Tue, Nov 25, 2008 at 9:30 AM, Nick <[EMAIL PROTECTED]>
>> >>>> >> >> > wrote:
>> >>>> >> >> >
>> >>>> >> >> > > I am having a very similar problem. Can someone give more
>> >>>> >> >> > > details
>> >>>> >> >> > > as
>> >>>> >> >> > > how to modify the JQ source file to fix this?
>> >>>> >> >> >
>> >>>> >> >> > > I have noticed (in Drip) that when I refresh the page, the
>> >>>> >> >> > > DOM
>> >>>> >> >> > > nodes
>> >>>> >> >> > > duplicate. This doesn't make any sense to me since I know
>> >>>> >> >> > > JQ
>> >>>> >> >> > > unbinds
>> >>>> >> >> > > everything on page unload in IE. This node duplication is
>> >>>> >> >> > > leading
>> >>>> >> >> > > to
>> >>>> >> >> > > some serious memory issues in my app that needs to run for
>> >>>> >> >> > > up
>> >>>> >> >> > > to 8
>> >>>> >> >> > > hours straight without a browser restart.
>> >>>> >> >> >
>> >>>> >> >> > > Any help would be much appreciated.
>> >>>> >> >> >
>> >>>> >> >> > > Thanks,
>> >>>> >> >> > > Nick
>> >>>> >> >> >
>> >>>> >> >> > > On Oct 24, 12:50 pm, chris robinson <[EMAIL PROTECTED]>
>> >>>> >> >> > > wrote:
>> >>>> >> >> > > > Hey all,
>> >>>> >> >> >
>> >>>> >> >> > > > I believe I have found a leak and have the beginnings of
>> >>>> >> >> > > > a
>> >>>> >> >> > > > solution
>> >>>> >> >> > > > to
>> >>>> >> >> > > > it.
>> >>>> >> >> >
>> >>>> >> >> > > > I'm writing an app that preforms ajax searching that
>> >>>> >> >> > > > returns
>> >>>> >> >> > > > pretty
>> >>>> >> >> > > > large result sets. I render them via jQuery into a
>> >>>> >> >> > > > tbody.
>> >>>> >> >> > > > once
>> >>>> >> >> > > > a
>> >>>> >> >> > > > subsequent search is performed I call tbody.empty() and
>> >>>> >> >> > > > append
>> >>>> >> >> > > > the
>> >>>> >> >> > > > new
>> >>>> >> >> > > > results. I created a test harness that would perform a
>> >>>> >> >> > > > predefined
>> >>>> >> >> > > > search 5000 times in a row with a good amount of time in
>> >>>> >> >> > > > between.
>> >>>> >> >> >
>> >>>> >> >> > > > I noticed that IE was allocating quite a bit of memory
>> >>>> >> >> > > > and
>> >>>> >> >> > > > never
>> >>>> >> >> > > > reclaiming it. At first I thought it was a closure or
>> >>>> >> >> > > > circular
>> >>>> >> >> > > > reference on my part. Once I was sure I had removed them
>> >>>> >> >> > > > I
>> >>>> >> >> > > > ran
>> >>>> >> >> > > > more
>> >>>> >> >> > > > test, sure enough it was still allocating a lot of
>> >>>> >> >> > > > memory.
>> >>>> >> >> > > > Through
>> >>>> >> >> > > > a
>> >>>> >> >> > > > lot of research I found this articlehttp://
>> >>>> >> >> > >www.scribd.com/doc/2159768/Ajax-Part2
>> >>>> >> >> > > > which says that JS's removeChild will leak in IE.
>> >>>> >> >> > > > Microsoft
>> >>>> >> >> > > > uses
>> >>>> >> >> > > > another method to remove which is essentially this:
>> >>>> >> >> >
>> >>>> >> >> > > > function DestroyElement(elem) {
>> >>>> >> >> > > > var garbageBin =
>> >>>> >> >> > > > document.getElementById('IEMemoryLeakGarbageBin');
>> >>>> >> >> > > > if(garbageBin === undefined) {
>> >>>> >> >> > > > garbageBin = document.createElement("DIV");
>> >>>> >> >> > > > garbageBin.id = "IEMemoryLeakGarbageBin";
>> >>>> >> >> > > > garbageBin.style.display = 'none';
>> >>>> >> >> > > > document.body.appendChild(garbageBin);
>> >>>> >> >> > > > }
>> >>>> >> >> > > > garbageBin.appendChild(elem);
>> >>>> >> >> > > > garbageBin.innerHTML = "";
>> >>>> >> >> >
>> >>>> >> >> > > > }
>> >>>> >> >> >
>> >>>> >> >> > > > I went through jQuery 1.2.6 and replaced the removeChild
>> >>>> >> >> > > > references
>> >>>> >> >> > > > with a check for IE, and if so use this, else use the
>> >>>> >> >> > > > regular
>> >>>> >> >> > > > removeChild. After doing so and rerunning my test I saw
>> >>>> >> >> > > > drastic
>> >>>> >> >> > > > improvements in memory being reallocated after my
>> >>>> >> >> > > > elements
>> >>>> >> >> > > > were
>> >>>> >> >> > > > removed from the document.
>> >>>> >> >> >
>> >>>> >> >> > > > I also ran these test on FF, with or without this change
>> >>>> >> >> > > > it
>> >>>> >> >> > > > ran
>> >>>> >> >> > > > the
>> >>>> >> >> > > > same way, recollecting memory correctly.
>> >>>> >> >> >
>> >>>> >> >> > > > this is only seems to be a drastic performance increase
>> >>>> >> >> > > > if
>> >>>> >> >> > > > you
>> >>>> >> >> > > > are
>> >>>> >> >> > > > creating 1000+ dom elements and binding events to them,
>> >>>> >> >> > > > but,
>> >>>> >> >> > > > the
>> >>>> >> >> > > > app
>> >>>> >> >> > > > I
>> >>>> >> >> > > > am writing has to be able to run all day with out leaving
>> >>>> >> >> > > > or
>> >>>> >> >> > > > refreshing the page.
>> >>>> >> >> >
>> >>>> >> >> > > > I just thought the Dev team might be interested in my
>> >>>> >> >> > > > findings.
>> >>>> >> >> > > > I
>> >>>> >> >> > > > plan on striping this down and writing conclusive tests
>> >>>> >> >> > > > and
>> >>>> >> >> > > > documentation over the weekend.
>> >>>> >> >> >
>> >>>> >> >> > > > -Chris
>> >>>> >> >> >
>> >>>> >> >> >
>> >>>> >> >>
>> >>>> >> >
>> >>>> >> >
>> >>>> >> > >
>> >>>> >> >
>> >>>> >>
>> >>>> >>
>> >>>> >>
>> >>>> >> --
>> >>>> >> Ariel Flesler
>> >>>> >> http://flesler.blogspot.com
>> >>>> >>
>> >>>> >>
>> >>>> >
>> >>>> >
>> >>>> > >
>> >>>> >
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Ariel Flesler
>> >>>> http://flesler.blogspot.com
>> >>>>
>> >>>>
>> >>>
>> >>
>> >>
>> >>
>> >
>> >
>> > >
>> >
>>
>>
>>
>> --
>> Ariel Flesler
>> http://flesler.blogspot.com
>>
>>
>
>
> >
>
--
Ariel Flesler
http://flesler.blogspot.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---