Re: repopulating my select



Hi Rob,

"RobG" <rgqld@xxxxxxxxxxxx> wrote in message
news:968978d6-3d84-4d7c-9879-d4a3e1f411b1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Oct 30, 7:56 am, "Richard Maher" <maher...@xxxxxxxxxxxxxxxxxx>
wrote:
Hi Davey,

"Davey" <daveyer...@xxxxxxxxx> wrote in message

news:tAmGm.40575$cL1.38933@xxxxxxxxxxxxxxx



"Davey" <daveyer...@xxxxxxxxx> wrote in message
news:iwmGm.40574$cL1.5400@xxxxxxxxxxxxxxx
to change the options in my select element
i set options.length to zero then use
y = document.createElement('option');
and add(y,null) in a loop
I'm wondering what happens to all

those option elements ?
should i delete them somehow ?
is this a "memory leak"

I use the following method (I think it was Roedy that showed me and will
be
in the archives some where if your interested.)

At load time, when you have an empty list, clone your select then when
you
need to tear down the list clone that node again and use replaceChild as
in: -

swapClone = selectClone.cloneNode(true);

If an empty list is required, then:

...cloneNode(false)

would be a better choice. It's worth noting that listeners may or may
not be cloned depending on how they were attached and which browser is
being used. This method doesn't break circular references involving
closures that may cause memory leaks, nor other references that may
prevent the nodes being garbage collected (and essentially become
memory leaks).


selectRef.parentNode.replaceChild(swapClone, selectRef);
selectRef = document.getJobs.jobList;

Seems to work pretty well, and the performance boost over a remove of
every
row is astounding!

It also fails in some older browsers (about Safari 1.3 I think) but
that may not matter much. Looping over child nodes and removing them
is suitably fast for most cases,

My experience has been that it is desperately slow in all but the most
trivial of cases. Yes, if you've got 20 options then evrything is easy; if
you've got 2000 rows in a result-set then it is sloooooww.

e.g. something like:

while (el.lastChild) {
el.removeChild(el.lastChild);
}

Sorry, just saw your doing a removeChild rather than and option remove. I've
never done it and will take your word for it.


which can also be adapted to remove listeners and references if
necessary.


--
Rob

Regards Richard Maher


.



Relevant Pages

  • Re: repopulating my select
    ... is this a "memory leak" ... It's worth noting that listeners may or may ... not be cloned depending on how they were attached and which browser is ... This method doesn't break circular references involving ...
    (comp.lang.javascript)
  • Re: How memory leaks in java
    ... >:Strictly speaking, you can't have a memory leak in Java, at least not ... I rather suspect that simple "circular" references, ... one of the strengths of Java). ... main startup method displayed that JWindow, ...
    (comp.lang.java.programmer)
  • Re: FYI: Creating circular references is a perfectly OK thing to do.
    ... be so, except that IE leaks. ... Circular references aren't bad per se. ... most widely-used browser. ... even smaller companies away from IE6. ...
    (comp.lang.javascript)
  • Re: Memory Leak due to objects not destroyed
    ... Are there any references to it ... >> nether destroyed till we exit app. ... >> I'm sure Garbage collection is made cause i logged memory usage ... >> I've succeeded in slowing down memory leak by overriding Dispose(bool ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: OO and game design questions
    ... pattern that would remember changes to an object, ... avoids being hit by the oncoming wall. ... references to it were replaced by references to the Deleted object. ... This memory leak was a known problem, but deemed to be small enough that ...
    (comp.lang.python)