Hi,

On Dec 3, 3:35 pm, Rob Cluett <rob.clu...@gmail.com> wrote:
> RE: Element.remove(DOMelement)
>
> Does this method remove all children of the specified DOMelement
> before removing the specified DOMelement or must I delete all of the
> DOMelements children, grandchildran, etc. first?

Removing an element, by its nature, removes all of its descendants.
Neither you nor Prototype needs to do anything special to make that
happen.

> RE: Element.stopObserving(DOMelement)
>
> Does this method remove all events being observed for the given
> DOMelement or must I stop each one individually?  At what point does
> this actually get removed from the DOM (garbage collection)?

Per the docs[1], if you call stopObserving without specifying either
an event name or a handler, all events hooked up to that element (via
Prototype) will be removed. They are removed from the element
immediately. When any memory consumed by those event handlers is
actually released is dependant on the browser's implementation and
varies dramatically across browsers.

> RE: Function.bindAsEventListener
>
> Should Element.StopObserving work to immediatly remove everything
> added to the DOM when using BindAsEventListener?

You almost certainly don't need to use bindAsEventListener; more here
[2]. Whether you use it or not, stopObserving removes the event
handler from the element immediately.

> I'm seeing a slew of memory leaks in my application and can only
> assume elements are not being removed from the DOM as they should be.
> Any help would be appreciated.  I'm going though the prototype.js code
> now by any insight would be great.  Thanks guys.

Be sure to disconnect events prior to removing elements, that could be
part of the problem. For example, if you have:

<div id='outer'>
    <div id='inner'>
    ...
    </div>
</div>

And you have:

    $('outer').observe('click', doSomething);
    $('inner').observe('click', doSomethingElse);

Suppose you do this:

    $('outer').remove();

You've just left two event handlers dangling around in memory.

Alternately, suppose you did this:

    $('outer').stopObserving().remove();

You've still left one event handler dangling around in memory, the one
on the 'inner' div. You'd need to do this to clean up completely:

    $('inner').stopObserving();
    $('outer').stopObserving().remove();

Your application logic needs to be sure it knows about handlers it
needs to remove. Although you could do this:

    var outer;
    outer = $('outer');
    outer.descendants().invoke('stopObserving');
    outer.stopObserving().remove();

...doing so is very inefficient.

[1] http://api.prototypejs.org/dom/event.html#stopobserving-class_method
[2] 
http://proto-scripty.wikidot.com/prototype:tip-you-probably-don-t-need-bindaseventlistener

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

--

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.


Reply via email to