Solved

Freeing Memory

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now