Note that MooTools has its own garbage collection. Any time you attach
something to an element (events, storage, etc) or reference an element with
a property in a class (as with Fx), so long as you use MooTools methods to
do this, you needn't worry about memory issues when you destroy that element
*provided you also use MooTools methods to destroy it*.
This means that you always use Element.addEvent to add events. You always
use Element.destroy or Element.dispose to remove an element. You always use
Element.set('html', yourHTML) to set the innerHTML of an element. Provided
you are always using MooTools to attach to elements and remove them, you
should be fine.
Note that MooTools classes that attach themselves to objects (like Fx, for
instance) and MooTools classes that destroy objects (as Request.HTML can do)
use MooTools methods for these things themselves, so they are safe to use
and reuse on the same DOM elements or newly created ones.
One final suggestion. If you have a DOM element with a bunch of
functionality that you keep destroying and re-attaching to, Might I
recommend that you have a class that manages all this for you? Your class
would be passed an element reference and it would attach all the events and
functionality to that element that it needs to, but it would store data and
state in the class (rather than on the element with storage). This class
would also have a method to update that element with Request.HTML and, when
that request was complete, it would create a new instance of itself with the
resulting new element.
This is a pattern I use often. Instead of a bunch of functionality attached
to the element, attach all your logic to a class and pass it your element.
It makes things easier to maintain but it also gives you access to all the
tools that Classes have (options, events, etc).
-Aaron
On Tue, Dec 16, 2008 at 9:23 AM, nwhite (via Nabble) <
[email protected]<ml-user%[email protected]>
> wrote:
> Is there a need for the same DOM element to be refreshed multiple time with
> the same data?
>
> Can you use a different approach, maybe append to the element instead of
> replacing?
>
> When you talk about 10+ pages and reloading the same element. How much data
> are you actually inserting each time?
>
> The browser garbage collection should be good enough to handle your case.
> Are you doing any kind of binding to the objects that are inserted?
> Creating closures with DOM elements will create memory leaks.
>
> Maybe this will put your mind at ease. Think of GMail. They are constantly
> replacing DOM elements and refreshing content. They rely heavily on the
> browsers automatic garbage collection.
>
>
>
>
>
> On Tue, Dec 16, 2008 at 11:46 AM, Xeoncross
> <xeoncr...@...<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=1663933&i=0>
> > wrote:
>
>>
>>
>>
>> On Dec 11, 10:45 am, aowie
>> <aow...@...<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=1663933&i=1>>
>> wrote:
>> > Why not define a variable in the JS your loading? Then when you go to
>> > make the request again, before the JS is loaded, check for that
>> > variable's existence. If it is defined, dont reload the js, if it
>> > isnt, let the user continue on their merry way without constantly
>> > reloading the same JS files.
>>
>>
>> No the problem isn't that I keep re-loading a JS file - the problem
>> is
>> that a DOM element (I keep attaching a lot of objects too) is removed
>> every ajax request and a new (identical) version is added (sometimes).
>>
>> So this means that everytime the new AJAX content comes in I have
>> to rescan for the element and reattach all this stuff to it. - So I
>> am
>> worried that after 10+ pages of this I will have a lot of wasted RAM.
>
>
>
>
> ------------------------------
> View message @
> http://n2.nabble.com/Handling-the-changing-DOM-structure-with-AJAX-forms-tp1623247p1663933.html
> To start a new topic under MooTools Users, email
> [email protected]<ml-node%[email protected]>
> To unsubscribe from MooTools Users, click here< (link removed) >.
>
>
>
-----
The MooTools Tutorial: http://www.mootorial.com www.mootorial.com
Clientcide: http://www.clientcide.com www.clientcide.com
--
View this message in context:
http://n2.nabble.com/Handling-the-changing-DOM-structure-with-AJAX-forms-tp1623247p1664301.html
Sent from the MooTools Users mailing list archive at Nabble.com.