title: ECMAScript 6: what is WeakSet for?
body: <p>The WeakSet is supposed to store elements by weak reference. That is, if an object is not referenced by anything else, it should be cleaned from the WeakSet.</p>
  
  <p>I have written the following test:</p>
  
  <pre><code>var weakset = new WeakSet(),
      numbers = [1, 2, 3];
  
  weakset.add(numbers);
  weakset.add({name: "Charlie"});
  
  console.log(weakset);
  
  numbers = undefined;
  
  console.log(weakset);
  </code></pre>
  
  <p>Even though my <code>[1, 2, 3]</code> array is not referenced by anything, it's not being removed from the WeakSet. The console prints:</p>
  
  <pre><code>WeakSet {[1, 2, 3], Object {name: "Charlie"}}
  WeakSet {[1, 2, 3], Object {name: "Charlie"}}
  </code></pre>
  
  <p>Why is that?</p>
  
  <p>Plus, I have one more question. What is the point of adding objects to WeakSets directly, like this:</p>
  
  <pre><code>weakset.add({name: "Charlie"});
  </code></pre>
  
  <p>Are those Traceur's glitches or am I missing something?</p>
  
  <p>And finally, what is the practical use of WeakSet if we cannot even iterate through it nor get the current size?</p>