Questioning WeakMap.prototype.clear (was: Private symbols as WeakMap sugar)

Allen Wirfs-Brock allen at
Mon Jan 21 11:34:40 PST 2013

On Jan 21, 2013, at 10:20 AM, Mark S. Miller wrote:

> Hi David, thanks for raising this. Not having been able to take much
> time lately, I had not been aware that a .clear method had been added.
> I think it's a terrible idea. I like your explanation of why --
> because of the simple property it breaks. Indeed, this violation
> contradicts the main use case of WeakMaps -- for soft fields.

I really have to disagree about the main use case of WeakMaps.  I asset that the main use is for representing an extensible set of external relationships among objects in a manner that does cause memory leaks. 

A soft field (and arguably all ES properties on non-sealed objects are themselves "soft field") is another way to represent such relationships.  Alternatively, if soft fields aren't available an external relationship store can be used to represent them.

Even if soft fields are a primary use case, nothing says that all soft fields must be high integrity fields just as  not all objects or object properties need to be high integrity properties.


More information about the es-discuss mailing list