title: Is WeakHashMap ever-growing, or does it clear out the garbage keys?
body: <p>I am trying to use <a href="https://docs.oracle.com/javase/10/docs/api/java/util/WeakHashMap.html" rel="nofollow noreferrer"><code>WeakHashMap</code></a> as a concurrent <a href="https://docs.oracle.com/javase/10/docs/api/java/util/Set.html" rel="nofollow noreferrer"><code>Set</code></a> of weak references. </p>
  
  <pre><code>    this.subscribers =
              Collections.synchronizedSet(
                      Collections.newSetFromMap(
                              new WeakHashMap &lt;&gt;()
                      )
              );
  </code></pre>
  
  <p>When an element goes to garbage-collection, my set continues to report it as a part of the collection. So it seems the map is ever-growing. </p>
  
  <p>The documentation says:</p>
  
  <blockquote>
    <p>When a key has been discarded its entry is effectively removed from the map,…</p>
  </blockquote>
  
  <p>But that does not seem to be the case in practice.</p>
  
  <p>Is there ever a point at which the <code>WeakHashMap</code> clears out the detritus?</p>