Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I clear an inputed integer from a variable? 1

Status
Not open for further replies.

imconfused86

Programmer
May 10, 2005
1
US
How can I clear a variable that already has an integer assigned to it so I can use that variable again later in the program?

i'm confused
wait...
maybe i'm not
 
You can set an Object to null, or a primitive to some kind of default value (eg, set an int to -1).

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Your question seems to hint at some deeper misunderstanding. Forgive me if I'm wrong.

A variable is just that - it can vary at the whim of the programmer. You don't need to clear a variable before using it for something else. It is down to you, however, to write your code to ensure that it isn't still being used for one task before putting it to use by another.

There is a case for 'clearing' variables which reference Objects as soon as you can, however (as sedj shows above). This might allow the garbage collector to recover the memory used by the object sooner if nothing else references it.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top