On Mon Jul 17 11:40:25 2023 +0000, Gabriel Ivăncescu wrote:
Ok, I think this should cover all cases, with updated tests included. For reference, I also took a brief look at how wine-gecko handles weak maps, and it seems to be pretty similar (in concept), so I think it's enough.
This extra complication to GC does not seem needed for me. As I mentioned earlier, if you track weak references, you could just use the existing traversal mechanism. To summarize: "zombie" objects are not great in the first place, the solution depends on GC to a degree that it doesn't need to, delays reclaiming memory even in simple cases and it makes GC more complicated than it needs to be. I'd expect that avoiding all this would make the code simpler.
For reference, I also took a brief look at how wine-gecko handles weak maps, and it seems to be pretty similar (in concept), so I think it's enough.
Aside from weak refs, as a side note, some (most?) of JS engine depend much more on GC for object handling than we do. They often don't track object ref count at all, so objects can't be freed any other way than by GC. In such implementations, essentially all unused objects are "zombies". This is not how our jscript works (while changing that may be theoretically possible, it does not really align with how jscript exposes its internals with IDispatch). We pay the price of tracking ref count, but benefit from the fact that we can reclaim memory immediately in simple cases, allowing GC to run less often and on smaller graphs.