title: Linked List Implementation In Java and Garbage Collection
body: <p>If I have a linked list structure, and I implement the clear() method as follows:</p>
  
  <pre><code>public void clear() {
      firstNode = null;
      size = 0;
  }
  </code></pre>
  
  <p>will it still get correctly garbage collected, or would I want to walk through each node, setting nextNode to null?</p>
  
  <p>None of the nodes can be directly referenced from outside the linked list, so there's no case where there would be a reference to any of them outside my class, but I'm unsure if Java would correctly garbage collect the remaining chained nodes.</p>