Yusuke SUZUKI (2015-06-17T02:25:23.000Z)
d at domenic.me (2015-07-07T01:36:35.544Z)
In ES6 spec, template site objects are strongly referenced by the realm.[[templateMap]]. 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 private symbols). Is it intentional semantics? I'd like to hear about this. (And please point it if I misunderstood)