GC and Linked List

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a link list; if I want to Clear the list do I have to set every node
in the list to null or I can simply set the Head/Tail nodes to null?

If I set Head/Tail to null, will the GC free any resources used by the nodes
between Head and Tail?
 
Maksim said:
I have a link list; if I want to Clear the list do I have to set every node
in the list to null or I can simply set the Head/Tail nodes to null?

If I set Head/Tail to null, will the GC free any resources used by the nodes
between Head and Tail?

If you just want to make sure it's all eligible for garbage collection,
why not just make sure you're not holding onto any references to the
list in the first place?

Other than that, it depends on the implementation, basically.
 
So if I have an object A referensing an object B and I set A = null, then B
also becomes eligible for GC?
 
Maksim said:
So if I have an object A referensing an object B and I set A = null, then B
also becomes eligible for GC?

Well, only if that was the only reference to A, and if A had the only
reference to B.
 
Back
Top