Re: repopulating my select
- From: RobG <rgqld@xxxxxxxxxxxx>
- Date: Thu, 29 Oct 2009 16:26:19 -0700 (PDT)
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, e.g. something like:
while (el.lastChild) {
el.removeChild(el.lastChild);
}
which can also be adapted to remove listeners and references if
necessary.
--
Rob
.
- Follow-Ups:
- Re: repopulating my select
- From: Richard Maher
- Re: repopulating my select
- References:
- repopulating my select
- From: Davey
- Re: repopulating my select
- From: Davey
- Re: repopulating my select
- From: Richard Maher
- repopulating my select
- Prev by Date: Re: Limit of 4K
- Next by Date: Re: repopulating my select
- Previous by thread: Re: repopulating my select
- Next by thread: Re: repopulating my select
- Index(es):
Relevant Pages
|