On Fri Jul 14 12:00:19 2023 +0000, Jacek Caban wrote:
Treating them as an object extension only would not handle things like:
var m = new WeakMap(); m.set(key, m); m = null;
We could instead traverse map entry value in step 2 of GC only when it's marked twice: once from the map and once from object itself. Unless I'm missing something, this should get all cases right.
I thought about this some more, I think what we need to do is to have an extra pass over weak maps only after step 2, and traversing/unmarking only those weak maps that are alive *and* those keys which are also alive in it (alive means they're not marked for garbage collection).
However, we have to keep re-iterating over the weak maps everytime we actually unmarked something during one iteration, because each unmarking can potentially make some other path "alive", and we don't want to mistakenly unlink them. And stop when during the entire iteration nothing additional has been unmarked / made alive.
This should cover all cases, and btw thanks for the test I'll add it just to make sure.