?
Solved

Freeing Memory

Posted on 2003-11-13
4
Medium Priority
?
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
lwinkenb earned 80 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 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