Re: Loading Dom nodes into Memory - best practise

"Ian Petersen" <[email protected]> Sun, 14 May 2006 13:06:13 -0400
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
Hi Richard,

Instead of just leaving the page open in your browser for a long time,
try refreshing the page several hundred times.

Holding DOM nodes in memory can cause a memory leak if you have any
circular references in your data structures.  The simplest circular
reference is a Javascript object that points to a DOM node that points
back to that same Javascript object.  Any circle is a problem, though,
so introducing extra Javascript objects or extra DOM nodes into the
circle doesn't solve the problem.

One particularly nasty trick in this problem is that event handlers
can be part of the circle.  Functions are Javascript objects and, when
they are closures, too, they can have references to other objects
(including DOM nodes).  (In case you've never heard of a closure, it's
basically a nested function.)

If you can refresh your test page a few hundred (or a few thousand)
times without crashing the browser, you're probably OK.  If the
browser eventually crashes, then you'll need to break the circular
references somehow.  You can either redesign your page to not create
the circles in the first place or you can add unload handlers that go
around breaking links as the browser dismantles the page.

Ian

On 5/14/06, Richard Garbutt <[email protected]> wrote:
> Hi,
>
> I'm working on a project where I'm manipulating elements on the page
> in response to user input. I've created objects which load the
> elements to be manipulated as member variables on page load. The
> objects provide an interface to manipulate the elements they are
> responsible for. The event handlers use this interface.
>
> This approach makes event handling very responsive, as no dom
> traversal is needed when the event fires. (Or very little - sometimes
> I use firstChild or previousSibling.)
>
> I'm wondering if there are any problems caused by loading dom nodes
> into browser memory and leaving them there for as long as the page is
> open in the user's browser. I'm loading about 20-50 nodes like this.
> Leaving the page open in Firefox and IE for several hours doesn't seem
> to cause any problems - but I have plenty of memory.
>
> regards,
> Richard
>
>
>
> Unsubscribe
> [email protected]
>
> List info
> http://www.quirksmode.org/dom/list.html
> Yahoo! Groups Links
>
>
>
>
>
>
>


-- 
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get to your groups with one click. Know instantly when new email arrives
http://us.click.yahoo.com/.7bhrC/MGxNAA/yQLSAA/9rHolB/TM
--------------------------------------------------------------------~-> 

Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/