19:10
<snek>
in implementations that model weakmaps as hidden fields on the keys, how do they in practice clean those up when the weakmap is no longer reachable?
19:48
<bakkot>
in implementations that model weakmaps as hidden fields on the keys, how do they in practice clean those up when the weakmap is no longer reachable?
I believe chakra works or worked that way; you could check
20:23
<Mathieu Hofman>
in implementations that model weakmaps as hidden fields on the keys, how do they in practice clean those up when the weakmap is no longer reachable?
From what I can tell, XS has a pointer from the key field back to the weak collection, and from the weak collection entry back to the key field, so that removal of either can remove the other. More specifically when doing the mark and sweep, the first pass mark the field on the key, then it checks the weak collection content, and if it's no longer reachable, it removes all the keys fields corresponding to the collection's entries: https://github.com/Moddable-OpenSource/moddable/blob/24e3e54fd3b66379c1f91ad92969c99f941ff4cf/xs/sources/xsMemory.c#L1595-L1609