Use cases for WeakMap

Oliver Hunt oliver at apple.com
Sat May 14 16:21:50 PDT 2011


On May 14, 2011, at 4:03 PM, David Bruant wrote:

> Le 15/05/2011 01:01, Oliver Hunt a écrit :
>> No, I am wrong, if i have a key that i can ever reuse, the map is strong, because the key will keep the value live.  These aren't weak maps, they are strong maps that don't leak keys that have become dead.
>> 
>> I can kind of see the value of this kind of structure, but I don't believe it is a WeakMap.
> What is your definition of a WeakMap?
> How is the current strawman different from this definition?

In the definition of a weak map that I have always known, the key does not keep the mapped value alive.  In the weakmaps proposal the key keeps the mapped value alive.

So if you can ever lookup a key again, the value cannot be collected, so your "cache" will hold onto every entry forever.

> David
--Oliver


More information about the es-discuss mailing list