leaks when using primitives; fixable with WeakRef
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- data
调研方向
首先定位 Tuple 和 UniversalWeakMap 的实现,然后跟踪 Tuple(primitive) 如何创建并保留父节点。将当前的强引用与提议的 WeakRef、FinalizationRegistry 和全局 WeakMap 方案进行比较;完成标准是:垃圾回收后,元组及其映射不再保留内存,包括各种由基本类型值组成的元组。
由索引模型根据 Issue 内容生成。
描述
The description claims "no leaks", but if you do Tuple(primitive), that creates a UniversalWeakMap which can never be garbage collected. If you're creating a lot of tuples with a lot of different primitives, that can be a problem.
Now that we have WeakRef and FinalizationRegistry, I'm pretty sure it's possible to do better, so that there's actually no leaks: that is, no matter how many tuples you create and how you create them, once they've all been GC'd you're guaranteed that no additional memory is held.
The necessary changes are:
- When
set(key, value)is called on aUniversalWeakMap, store aWeakReftovalueinstead of storingvaluedirectly, and registervaluein aFinalizationRegistryso that when it is collectedkeyis cleared from the map. - Use a global
WeakMapto store a map from each created tuple to all of its parent nodes.
Then the only strong references to UniversalWeakMap objects (except the root) are from the tuples stored in those maps. Once all the tuples stored in a given UniversalWeakMap are GC'd, it can be GC'd as well.
The only caveat with this approach is if the user uses a tuple as a key in a weak collection. In that case the tuple can still get collected even if it was only holding primitives, which might be surprising. But that's unavoidable if avoiding leaks.
- 主要语言
- JavaScript
- 星标
- 38
- 派生
- 3
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
benjamn/immutable-tuple 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
benjamn/immutable-tuple#10 ·
-
难度 3/5 1-2 天 新手友好度 42/100
-
难度 2/5 1-3 小时 新手友好度 35/100
benjamn/immutable-tuple#6 · 2 条评论 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 20/100
-
难度 3/5 1-2 天 新手友好度 30/100
查看 benjamn/immutable-tuple 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
Automattic/node-canvas#2633 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
capricorn86/happy-dom#2594 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 79/100
microsoft/monaco-editor#5575 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复