The WeakSet object allows the users to store weakly held objects in a collection.
WeakSet objects are collections of objects. An object in the WeakSet may occur only once. It is unique in the WeakSet’s collection. The main differences to the Set object are:
- Unlike Set, WeakSets are collections of objects only and not of arbitrary values of any type.
- The WeakSet is weak. References to objects in the collection are held weakly. If there is no other reference to an object stored in the WeakSet , they can be garbage collected. That also means that there is no list of current objects stored in the collection. WeakSets are not enumerable.