Solved

Freeing link list

Posted on 1998-07-06
1
186 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
[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
1 Comment
 
LVL 16

Accepted Solution

by:
imladris earned 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

624 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