P
petermichaux
Hi,
I'm working on a JavaScript drop-down menu and have come across a
general question about garbage collection. Often in user interfaces you
don't need to keep a reference to a object that is controlling the
widget. You just need to set up the widget and let it live out it's
life being controlled by the object. It could be something like this
<ul id="tinyMenu">
<li>One</li>
<li>Two</li>
</ul>
<script>
function Menu(element) {
// initialize the menu
}
new Menu(document.getElementById("tinyMenu"));
</script>
Could garbage collection cause trouble in this case?
I don't really want to set some dummy variable equal to the new Menu
object. I just don't need to know about the menu anymore. I have this
same issue nested deeper in my code and if garbage collection won't
hurt me then I'd be happier with the simpler code.
Thanks,
Peter
I'm working on a JavaScript drop-down menu and have come across a
general question about garbage collection. Often in user interfaces you
don't need to keep a reference to a object that is controlling the
widget. You just need to set up the widget and let it live out it's
life being controlled by the object. It could be something like this
<ul id="tinyMenu">
<li>One</li>
<li>Two</li>
</ul>
<script>
function Menu(element) {
// initialize the menu
}
new Menu(document.getElementById("tinyMenu"));
</script>
Could garbage collection cause trouble in this case?
I don't really want to set some dummy variable equal to the new Menu
object. I just don't need to know about the menu anymore. I have this
same issue nested deeper in my code and if garbage collection won't
hurt me then I'd be happier with the simpler code.
Thanks,
Peter