Link to home
Start Free TrialLog in
Avatar of sre22
sre22

asked on

Freeing Memory

After your program is done with a certain object, is it good practice to set that object to null in order to free memory?  Or what is preferred method if there is one?
ASKER CERTIFIED SOLUTION
Avatar of lwinkenb
lwinkenb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sre22
sre22

ASKER

>>when there are no more references to it.

what do you mean by this?  Does my program know when will be the last time I use an object and automatically delete it after the last time?
>>what do you mean by this?  Does my program know when will be the last time I use an object and automatically delete it after the last time?

Pretty much, yes.  The JVM keeps track of how many references an object has (among other things), and when it reaches 0, that object's memory is freed up for use.  The actual method the JVM uses is a bit more complex than a simple reference counter, but I hope you get the picture.
Avatar of sre22

ASKER

sounds good to me.  Thanks.