Matt Kruse wrote:
kaeli wrote: selectObj.options.length=0
I'm curious if this method actually destroys the option object, from a
memory management POV...
Do you know?
I'm not sure if there is any way to verify it, but I would suspect that the
options are garbage collected since they no longer have any references to
them.
The Option objects associated with the collection would not be "destroyed", but
they will become eligible for garbage collection because there are no further
references pointing to them. Any implementation that does not remove each
<select>.options[i] reference to it's associated Option object is in error, and
that would be the source of a "memory leak".
Note that you can cause your own "memory leaks" through sloppy coding
practices. If outside of any function you did something like:
var myOption;
for (var i = 0; i < anArray.length; i++) {
myOption = new Option(anArray[i], anArray[i]);
mySelect.options[mySelect.length] = myOption;
}
mySelect.options.length = 0;
At this point, myOption still contains a reference to the last Option object
you created, so it will never be garbage collected, even though the the length
of the select of which it's a member has been set to zero. If the above code is
in a method then "myOption" becomes eligible for garbage collection once the
method exits.
In the real world, I doubt the resourced used by one (or even 100) Option
objects is significant enough to worry about.
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html