weixin_39939601
weixin_39939601
2020-12-27 14:03

review: "Choose any such cell" underspecified?

(editor review per #110)

https://tc39.github.io/proposal-weakrefs/#sec-%finalizationgroupcleanupiterator%.next

Choose any such cell

This seems very underspecified - is there a reason not to specify the ordering of calling the callback for empty cells? I'd assume it'd be in register order.

该提问来源于开源项目:tc39/proposal-weakrefs

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39775106 weixin_39775106 4月前

    Yes, this is deliberate. It's unclear to me how an ordering should be implemented without significant extra memory overhead just for this particular purpose. Garbage collection is highly variable and nondeterministic, with or without this ordering, so it's unclear to me why these extra resources should be invested.

    点赞 评论 复制链接分享
  • weixin_39939601 weixin_39939601 4月前

    The List of cells is already kept - obviously a spec List need not exist as a reified list in the engine, but can you help me understand some possible implementation strategies where keeping an ordered list would create overhead?

    点赞 评论 复制链接分享
  • weixin_39775106 weixin_39775106 4月前

    In some implementations, there could be an object corresponding to the registration of an object in a FinalizationGroup which simply points to the FinalizationGroup, rather than the FinalizationGroup actually containing this list.

    点赞 评论 复制链接分享
  • weixin_39939601 weixin_39939601 4月前

    With that kind of one-way connection - ie, the object can't be reached from the FinalizationGroup - how would the FinalizationGroup Cleanup Iterator be able to jump to each one, without keeping some kind of construct that pointed to every object linked with the FG?

    点赞 评论 复制链接分享
  • weixin_39775106 weixin_39775106 4月前

    When a dead registration is found by the GC, then that could be put on a list within the FinalizationGroup. But the original ordering may be lost at this point.

    点赞 评论 复制链接分享
  • weixin_39980929 weixin_39980929 4月前

    What describes is exactly what happened when I rewrote that part of my shim: I didn't need to hold an ordered list of cells anymore so I just kept a map and took the list of finalized target info in whatever order the implementation is giving me, and include all the corresponding holdings (may be multiple per target).

    点赞 评论 复制链接分享
  • weixin_39775106 weixin_39775106 4月前

    Does the above example from answer your question?

    点赞 评论 复制链接分享

相关推荐