473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Garbage Collection and User Interfaces?

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

Mar 19 '06 #1
1 1088
pe**********@gmail.com said on 19/03/2006 6:47 PM AEST:
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?
What do you mean by 'cause trouble'? In the above, calling - new Menu()
- creates a new instance of the Menu object. But since it's not
assigned to anything, nothing has a reference to it unless you set up
some closures internally. After it's finished, it will be destroyed
when the garbage collector next runs. Even if it wasn't, because you
haven't assigned it to any variable you can't get a reference to it
(except for closures).

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.


You want the new Menu object to persist, but you don't use it? Why
bother with the 'new' keyword at all? I can only presume you are using
'new' because you also use 'this' inside Menu(). Internally, Menu can
refer to itself with arguments.callee, which is not quite the same as
using 'this' but there are ways to make it work.

Alternatively, you could use:

var tempObj = new Menu();

tempObj = null;

In which case the instance of Menu formerly referred to be tempObj no
longer has anything referencing it and it can be garbage collected.

If, on the other hand, you want the new instance of Menu to persist,
then you have to keep a reference to it. Post a bit more of what you
are trying to do that shows how Menu is used and maybe you'll get more
precise advise. :-)
--
Rob
Mar 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Sun | last post by:
Dear Group Gurus, If I use a COM class in my C# code, will the memory used by COM object be garbage collected, or do I have to manually collect it. Thanks, John
8
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
1
by: dd | last post by:
I have a situation where the browser memory goes up and up as each Ajax call causes new content to be deployed into a DIV. I'd like to know if I can force garbage collection to occur. More...
2
by: roger.dunham | last post by:
I am trying to identify whether a .NET 1.1 application that I have written has a memory leak. I thought I understood how .NET memory management worked, but it appears that there is more to it...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
72
by: Sebastian Nibisz | last post by:
SGCL is precise, parallel garbage collection library for C++ (at this time for Windows 32/64 only). SGCL is free software published under University of Illinois/NCSA Open Source License. Get it...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.