Re: repopulating my select
- From: "Richard Maher" <maher_rj@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 31 Oct 2009 05:42:34 +0800
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>be
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
youin the archives some where if your interested.)
At load time, when you have an empty list, clone your select then when
everyneed 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
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
.
- References:
- repopulating my select
- From: Davey
- Re: repopulating my select
- From: Davey
- Re: repopulating my select
- From: Richard Maher
- Re: repopulating my select
- From: RobG
- repopulating my select
- Prev by Date: Re: js form stripslashes function has errors
- Next by Date: Re: js form stripslashes function has errors
- Previous by thread: Re: repopulating my select
- Next by thread: Re: repopulating my select
- Index(es):
Relevant Pages
|