Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Freeing link list

Posted on 1998-07-06
1
Medium Priority
?
203 Views
Last Modified: 2010-04-16
I have a program which contains a complicate link-list.  If I free the header of the link-list, does Java garbage collection free the whole link-list for me or do I need to remove the reference for each link in the list?  Right now, I have a lot of memory problem with this program.  Without destructor method like in C++, I don't know how to free all of instances of objects created by "new" methods.
0
Comment
Question by:QianYang
1 Comment
 
LVL 16

Accepted Solution

by:
imladris earned 300 total points
ID: 1224882
Yes, Java garbage collection takes care of freeing the memory. One fly in the ointment could be that there are other references to elements in the list, elsewhere in the program. As long as anything is referenced, by any "live" (in scope) variable, the garbage collector will not be able to free those objects. If there are such variables, the solution is to assign them "null" so as to remove the reference.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

877 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