知识卡片
弱引用不延长对象寿命
Weak不会阻止对象在强引用归零时析构,但引用计数的管理分配还需等弱引用也释放后回收。因而“对象已销毁”与“管理内存已回收”是两件事。upgrade必须处理对象已不存在的情况,不能把Weak当成总有效引用。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 1. Types Smart Pointer Types · 查看原书依据
bookkeeping structure is dropped only when the weak reference count also drops to zero. An Rc on its own gives you the ability to reach an item in different ways, but when you reach that item, you can modify it (via get_mut) only if there are no other ways to reach the item—i.e., there are no other extant Rc or Weak references to the same item. That’s hard t
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Smart Pointer Types》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u046-ch01-065)。
- 结论依据:原文在“bookkeeping structure”附近的定义、例子或代码支撑本卡核心说明:Weak不会阻止对象在强引用归零时析构,但引用计数的管理分配还需等弱引用也释放后回收。边界按已读前提解释;示例未执行。
- 原始内容:bookkeeping structure is dropped only when the weak reference count also drops to zero. An Rc on its own gives you the ability to reach an item in different ways, but when you reach that item, you can modify it (via get_mut) only if there are no other ways to reach the item—i.e., there are no other extant Rc or Weak references to the same item. That’s hard t