Garbage collection after removing child nodes

Discussion in 'Javascript' started by Tim Streater, Feb 29, 2008.

  1. Tim Streater

    Tim Streater Guest

    I have a <select> that I build up dynamically. To later clear and
    repopulate it, I can't use the standard trick of:

    ptr_to_select.options.length = 0;

    because sometimes the <select> will contain <optgroup>s. These stay in
    the <select> (for Firefox and IE7, not Safari), after setting the length
    to zero.

    What seems to work on all browsers is:

    while (ptr_to_select.childNodes.length>0)
    {
    ptr_to_select.removeChild (popup.lastChild);
    }

    but, are the removed children properly garbage collected? Especially as
    some will be the <optgroup>s and have children themselves.
    Tim Streater, Feb 29, 2008
    #1
    1. Advertising

  2. Tim Streater wrote:

    > I have a <select> that I build up dynamically. To later clear and
    > repopulate it, I can't use the standard trick of:
    >
    > ptr_to_select.options.length = 0;
    >
    > because sometimes the <select> will contain <optgroup>s. These stay in
    > the <select> (for Firefox and IE7, not Safari), after setting the length
    > to zero.
    >
    > What seems to work on all browsers is:
    >
    > while  (ptr_to_select.childNodes.length>0)
    >      {
    >      ptr_to_select.removeChild (popup.lastChild);
    >      }
    >
    > but, are the removed children properly garbage collected? Especially as
    > some will be the <optgroup>s and have children themselves.


    The only way to know is to test with heavy data, and then see how many
    CPU is freed by the browser after the delete-action is finished.

    --
    Bart
    Bart Van der Donck, Mar 1, 2008
    #2
    1. Advertising

  3. Bart Van der Donck wrote:
    >> [...] are the removed children properly garbage collected? Especially as
    >> some will be the <optgroup>s and have children themselves.

    >
    > The only way to know is to test with heavy data, and then see how many
    > CPU is freed by the browser after the delete-action is finished.


    Memory (RAM), not CPU.


    PointedEars
    Thomas 'PointedEars' Lahn, Mar 1, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    373
    Roedy Green
    Jan 19, 2006
  2. Replies:
    3
    Views:
    20,999
    Martin Honnen
    Oct 4, 2005
  3. Replies:
    1
    Views:
    567
    Soren Kuula
    Aug 24, 2006
  4. Replies:
    1
    Views:
    1,202
    Joe Kesselman
    Nov 1, 2006
  5. Øyvind Isaksen
    Replies:
    1
    Views:
    960
    Øyvind Isaksen
    May 18, 2007
Loading...

Share This Page