Garbage collection and linked lists

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

Is it safe to use linked lists of objects or is it likely that garbage
collection will dump the nodes?
thanks
 
Hello Claire,

Garbage collection won't dump anything having references to it. On the other
hand, GC is capable of correctly handling circular references, so if there
are two objects referencing each other, but there are no other references to
these objects, the objects will be dumped. So yes, it is absolutely safe to
use linked lists - just make sure to clear all references to a node being
removed from the list for it to be collectible for the GC.
 
Back
Top