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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top