On Aug 11, 2007, at 4:38 AM, RobG wrote:
> On Aug 10, 6:26 am, Tom Gregory <[EMAIL PROTECTED]> wrote:
>> ... and I neglected to mention, you may also see speedup by appending
>> your new elements to a "holder" div that's not attached to the DOM,
>> then attaching them to the DOM all at once at the end of the loop.
>
> The following article on MSDN suggests that isn't a good idea as it
> may cause a memory leak:
>
> <URL: http://msdn2.microsoft.com/en-us/library/Bb250448.aspx >

Cool article.  Thanks for the link.
I'm not entirely sure the leak applies in this situation, though.   
It's emphasized that the (very small) leak is caused when this is  
done with elements that have inline scripts.  It doesn't explain  
whether scripts attached via attachEvent (or in Prototype,  
Event.Observe) would also have this problem.  I'd have to test it.

The workaround they suggest is to append elements as I described,  
then go back and attach scripts once all of the elements are in the  
DOM.  In the project at hand, one of the recommendations to Tom was  
to attach observers farther up the tree than he's doing, so this  
approach would be trivial.

 From the article: "The key points to understand about the leak are  
that DOM elements are being created with scripts already attached.  
This is actually crucial to the leak, because if we create DOM  
elements that don't contain any script and attach them together in  
the same manner we don't have a leak problem. This gives rise to a  
second workaround that might be even better for larger subtrees (in  
the example we only have two elements, so building the tree off the  
primary DOM isn't a performance hit). The second workaround would be  
to create your elements with no scripts attached initially so that  
you can safely build your subtree. After you've attached your subtree  
to the primary DOM, go back and wire up any script events at that  
point. Remember to follow the principles for circular references and  
closures so you don't cause a different leak in your code as you hook  
up your events."

Again, thanks for the link--it was an interesting article.



TAG


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to