dojo.connect has two parts in 0.9.

_base/connect.js contains the pure Javascript (i.e. DOM-less) connect
code, while _base/event.js contains the DOM aware version, including the
browser event normalization magic.

IE<7 has a well known leak pattern wrt circular connections between DOM
and JS. Former solutions for this leak pattern have tended to impair the
general GC-friendliness of the connect code.

I believe the new system is GC-friendly on most browsers, while still
protecting against connect leaks on IE<7.

Running this by contribs for sanity check, before embarking on full
documentation.

Questions

* Are there mistaken assumptions regarding the GC?
* Are there other memory leak patterns to worry about?
* Are there browsers othan than IE that have an issue with DOM/Js
circular references?

Connect

The implementation of dojo.connect has the source maintain a collection
of target references.

Because only the source holds the target references, disposing the
source is enough to remove all references created by dojo.connect. In
other words, there is no bookkeeping information created by dojo.connect
that will be problematic for garbage collection.

Sometimes a target circularly references a source. This is only a
problem on IE prior to version 7, where circular references between DOM
and JavaScript can cause memory leaks.

DOM Nodes

If dojo.connect detects a DOM node as the source, it passes control to
dojo.addListener (event.js).

AddListener Fast Path

On non-IE browsers, dojo. addListener uses the Node.addEventListener
built-in.

AddListener on IE 7

On IE7, addListener uses dojo.connect.

AddListener on IE <7

On IE6 and below, addListener uses a custom connection with a hash map
to prevent the source from referencing any targets directly and avoiding
any circular reference leaks. This solution requires storing a list of
targets separately. So the target references are not automatically
released with source, as with the fast-path implementation. Calling
disconnect will release a target.

Regards,
Scott J. Miles
TurboAjax Group
http://www.turboajax.com

Search Discussions

  • Adam L. Peller at Apr 24, 2007 at 8:57 am
    It's not event-related, but there's also the removeChild leak on IE:

    http://trac.dojotoolkit.org/ticket/1727

    The only solution we could find last time around was to wrap all the
    removeChild/Children calls. This was made more complicated by the
    fact that the old dojo.html code, like the DOM, used to return the
    node in question, so it had to run in two modes -- one to destroy it
    and one to just detach it. If we had new APIs that didn't return the
    node, I think we'd be better off.

    -Adam
    On 4/23/07, Scott J. Miles wrote:
    dojo.connect has two parts in 0.9.

    _base/connect.js contains the pure Javascript (i.e. DOM-less) connect
    code, while _base/event.js contains the DOM aware version, including the
    browser event normalization magic.

    IE<7 has a well known leak pattern wrt circular connections between DOM
    and JS. Former solutions for this leak pattern have tended to impair the
    general GC-friendliness of the connect code.

    I believe the new system is GC-friendly on most browsers, while still
    protecting against connect leaks on IE<7.

    Running this by contribs for sanity check, before embarking on full
    documentation.

    Questions

    * Are there mistaken assumptions regarding the GC?
    * Are there other memory leak patterns to worry about?
    * Are there browsers othan than IE that have an issue with DOM/Js
    circular references?

    Connect

    The implementation of dojo.connect has the source maintain a collection
    of target references.

    Because only the source holds the target references, disposing the
    source is enough to remove all references created by dojo.connect. In
    other words, there is no bookkeeping information created by dojo.connect
    that will be problematic for garbage collection.

    Sometimes a target circularly references a source. This is only a
    problem on IE prior to version 7, where circular references between DOM
    and JavaScript can cause memory leaks.

    DOM Nodes

    If dojo.connect detects a DOM node as the source, it passes control to
    dojo.addListener (event.js).

    AddListener Fast Path

    On non-IE browsers, dojo. addListener uses the Node.addEventListener
    built-in.

    AddListener on IE 7

    On IE7, addListener uses dojo.connect.

    AddListener on IE <7

    On IE6 and below, addListener uses a custom connection with a hash map
    to prevent the source from referencing any targets directly and avoiding
    any circular reference leaks. This solution requires storing a list of
    targets separately. So the target references are not automatically
    released with source, as with the fast-path implementation. Calling
    disconnect will release a target.

    Regards,
    Scott J. Miles
    TurboAjax Group
    http://www.turboajax.com
    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://dojotoolkit.org/mailman/listinfo/dojo-contributors

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdojo-contributors @
categoriesdojo
postedApr 23, '07 at 1:42p
activeApr 24, '07 at 8:57a
posts2
users2
websitedojotoolkit.org

2 users in discussion

Scott J. Miles: 1 post Adam L. Peller: 1 post

People

Translate

site design / logo © 2022 Grokbase