在 C# 中使用弱引用的 GC 成本?

发布于 2024-09-01 11:02:43 字数 380 浏览 1 评论 0原文

另一个问题中,斯蒂芬 C 说:

第二个担忧是 使用弱的运行时开销 参考。明显的成本是 那些创建弱引用和 打电话给他们。一个不太明显的 成本是大量的额外工作 每次GC时都需要完成 运行。

那么弱引用的 GC 成本到底是多少呢?它需要做哪些额外的工作,这有多大?我可以做出一些有根据的猜测,但我对实际的机制感兴趣。

In another question, Stephen C says:

A second concern is that there are
runtime overheads with using weak
references. The obvious costs are
those of creating weak references and
calling get on them. A less obvious
cost is that significant extra work
needs to be done each time the GC
runs.

So what exactly is the cost to the GC of a weak ref? What extra work does it need to do, and how big of a deal is it? I can make some educated guesses, but am interested in the actual mechanics.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2024-09-08 11:02:43

请查看 Jeffrey Richter 关于.NET 中的内存管理的文章,它必须清除稍微把事情搞起来。

Please check Jeffrey Richter's article about Memory Management in .NET it must clear up things a little.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文