Template site objects and WeakMap
utatane.tea at gmail.com
Wed Jun 17 02:25:23 UTC 2015
In ES6 spec, template site objects are strongly referenced by the
So naive implementation leaks memory because it keeps all the site objects
in the realm.
However, we can alleviate this situation.
Because template site objects are frozen completely, it behaves as if it's
a primitive value.
It enables the implementation to reference it from the realm weakly. When
all disclosed site objects are not referenced, we can GC them because
nobody knows the given site object is once collected (& re-generated).
But, even if the object is frozen, we can bind the property with it
indirectly by using WeakMap.
As a result, if the site objects are referenced by the realm weakly, users
can observe it by using WeakMap.
To avoid this situation, we need to specially handle template site objects
in WeakMap; WeakMap refers template site objects strongly (if we choose the
weak reference implementation for realm.[[templateMap]]).
But this may complicate the implementation and it may prevent implementing
WeakMap as per-object table (it can be done, but it is no longer simple
Is it intentional semantics? I'd like to hear about this.
(And please point it if I misunderstood)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss