title: clear() impl in Java's LinkedList
body: <p>I fear this is a really stupid question, but here goes:</p>
  
  <p>Why does the clear method in Java's default LinkedList implementation bother to walk the list and unhook all the nodes?  Why not just unhook the header and leave the rest of the list connected -- the GC will get it anyway, no?</p>
  
  <p>Here's the method:</p>
  
  <pre><code>/**
   * Removes all of the elements from this list.
   */
  public void clear() {
      Entry&lt;E&gt; e = header.next;
      while (e != header) {
          Entry&lt;E&gt; next = e.next;
          e.next = e.previous = null;
          e.element = null;
          e = next;
      }
      header.next = header.previous = header;
      size = 0;
  modCount++;
  }
  </code></pre>
  
  <p>Why walk it?  Why not just skip to <code>header.next = header.previous = header;</code>?</p>
  
  <p>Best I can figure is it helps the GC...?  This link <a href="http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#997442" rel="noreferrer">http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#997442</a> sort of suggests that.</p>
  
  <p>TIA...</p>