WeakSets

Whereas a WeakMap holds its keys weakly (but its values strongly), a WeakSet holds its values weakly (there aren’t really keys).

  1. var s = new WeakSet();
  2. var x = { id: 1 },
  3. y = { id: 2 };
  4. s.add( x );
  5. s.add( y );
  6. x = null; // `x` is GC-eligible
  7. y = null; // `y` is GC-eligible

Warning: WeakSet values must be objects, not primitive values as is allowed with sets.