Mozilla

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Keeping variables for each tab/window + Avoiding memory leaks

    3 answers - 2904 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Two question about Firefox extension development in XUL.
    Related to Semantic Radar - an extension that I am developing:
    1) Keeping variables for each tab/window
    I need to keep the state (indicating of links to particular types of
    RDF are present) for each window and tab. You can think of it as
    similar to detecting presence of links to RSS feeds and then saving
    them.
    Looked at using global variables which are kept separate for each
    browser window. But I see that they are shared between tabs which does
    not help.
    Q: How can an extension attach some variables to the current
    window/tab?
    There are a number of cases where this can be used - e.g., here instead
    of wasting the time running detection ( detectRDF() )at every tab
    change it would be done just once. A "naive" solution would be to add
    it as an attribute to some XUL element - similar as currently used to
    attach state information to the icom: item.setAttribute("mystate",
    "on");
    Hope there is a better solution.
    2) Cleanup / Avoiding memory leaks
    How to write the extension correctly and clean up to avoid memory
    leaks?
    My extension does the following calls on the initialisation:
    getBrowser().addEventListener("load", detectRDF, true);
    getBrowser().addEventListener("select", detectRDF, true);
    ();
    getBrowser().addEventListener("unload", function(e) {
    () }, false );
    I hope it cleans up the observer when not needed. Do I also have to
    unload event listeners and if yes - how? Also: the "unload" events
    trigger each time when a page is closed - that is too often to do
    removing of the resources used by the extension (I may be wrong here).
    The same with registration of resources - when to do it? "load" event
    is too often either.
    E.g., in the preferences tutorial [1] the startup() is launched on
    "load" events, causing [ ("", this, false); ] to
    be called each time. While this probably does not do harm (as opposed
    to not cleaning up and leaking memory) the question is - what is the
    correct way to do startup and cleanup for Mozilla extensions?
    [1]
    If you want to see the extension in action, install it and go to [2-4].
    You should see status bar icons appear to indicate presence of links to
    RDF metadata. Pressing the icons will lead you to a browser for this
    type of data.
    [2] http://b4mad.net/datenbrei/
    [3]
    [4]
    P.S. The link posted above is a development version. I should remove
    information of compatiblity with Mozilla Suite or fix it before
    releasing because the recent changes broke SemRadar's compatiblity with
    it.
    All feedback is welcome :)
    Thanks,
    Uldis
    [ http://captsolo.net/info/ ]
    dev-tech-xul mailing list
    dev-tech-xul (AT) lists (DOT) mozilla.org
  • No.1 | | 2153 bytes | |

    23 Aug 2006 13:44:34 -0700, Uldis Bojars <captsolo (AT) gmail (DOT) comwrote:
    1) Keeping variables for each tab/window
    []
    Q: How can an extension attach some variables to the current
    window/tab?

    There are a number of cases where this can be used - e.g., here instead
    of wasting the time running detection ( detectRDF() )at every tab
    change it would be done just once. A "naive" solution would be to add
    it as an attribute to some XUL element - similar as currently used to
    attach state information to the icom: item.setAttribute("mystate",
    "on");

    Hope there is a better solution.

    It's ok to store things as attributes (or even properties) on the
    browser/tab elements. In Firefox 2, you can hook into session store to
    save these values across sessions and closing/reopening tabs (see
    )

    2) Cleanup / Avoiding memory leaks

    How to write the extension correctly and clean up to avoid memory
    leaks?

    My extension does the following calls on the initialisation:
    getBrowser().addEventListener("load", detectRDF, true);
    getBrowser().addEventListener("select", detectRDF, true);
    ();
    getBrowser().addEventListener("unload", function(e) {
    () }, false );

    The extension should do any per-window initialization in the "load"
    listener on the |window| and do the cleanup in the "unload" listener.
    Note that your unload listener is set on the browser node, not the
    window. I'm not sure you'll get the window's unload notification in
    this setup, and as you noticed, you'll get the unload events from
    content. You can check the event's target to see where the event comes
    from, if desired.

    E.g., in the preferences tutorial [1] the startup() is launched on
    "load" events, causing [ ("", this, false); ] to
    be called each time.
    []
    [1]

    That's definitely not intended and I don't believe this to be true.
    Are you sure the example extension provided behave as you described?

    Nickolay

    dev-tech-xul mailing list
    dev-tech-xul (AT) lists (DOT) mozilla.org
  • No.2 | | 509 bytes | |

    23 Aug 2006 13:44:34 -0700, Uldis Bojars <captsolo (AT) gmail (DOT) comwrote:
    Do I also have to unload event listeners and if yes - how?

    Unless your listener doesn't let the document be destroyed, you don't
    have to remove it manually. Removing listeners can be done by calling
    removeEventListener on the same object and with the same params (sans
    last boolean param).

    Nickolay

    dev-tech-xul mailing list
    dev-tech-xul (AT) lists (DOT) mozilla.org
  • No.3 | | 3335 bytes | |

    Uldis Bojars wrote:
    Two question about Firefox extension development in XUL.

    Related to Semantic Radar - an extension that I am developing:

    1) Keeping variables for each tab/window

    I need to keep the state (indicating of links to particular types of
    RDF are present) for each window and tab. You can think of it as
    similar to detecting presence of links to RSS feeds and then saving
    them.

    Looked at using global variables which are kept separate for each
    browser window. But I see that they are shared between tabs which does
    not help.

    Q: How can an extension attach some variables to the current
    window/tab?

    There are a number of cases where this can be used - e.g., here instead
    of wasting the time running detection ( detectRDF() )at every tab
    change it would be done just once. A "naive" solution would be to add
    it as an attribute to some XUL element - similar as currently used to
    attach state information to the icom: item.setAttribute("mystate",
    "on");

    Hope there is a better solution.

    Sounds like you want to store something per top-level document, not per
    tab or window.

    How should that behaviour react to, say DM modifications, or loading
    the same page in two windows?

    If you're worried about memory impact, you may want to do a service that
    stores the last, say 12 recently used tabs, or something like that.
    And purges entries on close or so.

    Axel

    2) Cleanup / Avoiding memory leaks

    How to write the extension correctly and clean up to avoid memory
    leaks?

    My extension does the following calls on the initialisation:
    getBrowser().addEventListener("load", detectRDF, true);
    getBrowser().addEventListener("select", detectRDF, true);
    ();
    getBrowser().addEventListener("unload", function(e) {
    () }, false );

    I hope it cleans up the observer when not needed. Do I also have to
    unload event listeners and if yes - how? Also: the "unload" events
    trigger each time when a page is closed - that is too often to do
    removing of the resources used by the extension (I may be wrong here).

    The same with registration of resources - when to do it? "load" event
    is too often either.

    E.g., in the preferences tutorial [1] the startup() is launched on
    "load" events, causing [ ("", this, false); ] to
    be called each time. While this probably does not do harm (as opposed
    to not cleaning up and leaking memory) the question is - what is the
    correct way to do startup and cleanup for Mozilla extensions?

    [1]

    If you want to see the extension in action, install it and go to [2-4].
    You should see status bar icons appear to indicate presence of links to
    RDF metadata. Pressing the icons will lead you to a browser for this
    type of data.

    [2] http://b4mad.net/datenbrei/
    [3]
    [4]

    P.S. The link posted above is a development version. I should remove
    information of compatiblity with Mozilla Suite or fix it before
    releasing because the recent changes broke SemRadar's compatiblity with
    it.

    All feedback is welcome :)

    Thanks,
    Uldis

    [ http://captsolo.net/info/ ]

    dev-tech-xul mailing list
    dev-tech-xul (AT) lists (DOT) mozilla.org

Re: Keeping variables for each tab/window + Avoiding memory leaks


max 4000 letters.
Your nickname that display:
In order to stop the spam: 3 + 2 =
QUESTION ON "Mozilla"

EMSDN.COM