Solved

Freeing Memory

Posted on 2003-11-13
4
248 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

810 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