title: Is Java HashMap.clear() and remove() memory effective?
body: <p>Consider the follwing <code>HashMap.clear()</code> code:</p>
  
  <pre><code> /**
   * Removes all of the mappings from this map.
   * The map will be empty after this call returns.
   */
  public void clear() {
      modCount++;
      Entry[] tab = table;
      for (int i = 0; i &lt; tab.length; i++)
          tab[i] = null;
      size = 0;
  }
  </code></pre>
  
  <p>It seems, that the internal array (<code>table</code>) of <code>Entry</code> objects is never shrinked. So, when I add 10000 elements to a map, and after that call <code>map.clear()</code>, it will keep 10000 nulls in it's internal array. So, my question is, how does JVM handle this array of nothing, and thus, is <code>HashMap</code> memory effective?</p>