On Thu, Sep 10, 2015 at 11:02 AM, Michael McGlothlin
<mike.mcgloth...@gmail.com> wrote:
> One issue I did notice with WeakMaps is that because it can't use primative 
> values as keys that they'll throw errors unless otherwise handled. Checking 
> if they are an instanceof Object and if not using a Map instead seems to work.
>
> I wouldn't think using primatives as WeakMap keys would be an issue.

Primitives have no notion of "reference" or "liveness". They can and
are destroyed and recreated all the time, or shared across multiple
independent non-communicating contexts.  As such, they aren't a
reliable key for WeakMaps, which keep their value alive "as long as
the key is alive".  Using a primitive string as a key can
inadvertently leak the value for a long time, as the key might be
interned and long-lived, far past the point when your code has dropped
the intended references to it.

~TJ
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to