Solved

Freeing Memory

Posted on 2003-11-13
4
246 Views
Last Modified: 2010-03-31
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?
0
Comment
Question by:sre22
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
lwinkenb earned 20 total points
ID: 9742693
The java garbage collector will automatically free the memory when there are no more references to it.
0
 

Author Comment

by:sre22
ID: 9742724
>>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?
0
 
LVL 5

Expert Comment

by:lwinkenb
ID: 9742795
>>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.
0
 

Author Comment

by:sre22
ID: 9742802
sounds good to me.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 83
Hibernate Not Rolling Back When something fails in a stored procedure 2 52
split string containing \r\n in Java 46 38
servlet example 17 12
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now