知识卡片
强计数决定值何时释放
Rc::strong_count(&a) 统计现存的有所有权句柄。克隆使计数加一,句柄析构使计数减一。最后一个强句柄消失后才销毁内部值。借用句柄本身不会创建新所有者。
相关卡片 [[Rc 共享同一份所有权]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 智能指针 Rc<T>, the Reference Counted Smart Pointer · 查看原书依据
We can see that the Rc<List> in a has an initial reference count of 1; then each time we call clone, the count goes up by 1. When c goes out of scope, the count goes down by 1.
参考来源
- 位置:《The Rust Programming Language(第2版)》第15章 智能指针(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c15.xhtml`,块 0215)
- 结论依据:原文说明克隆增加、作用域结束自动减少计数。
- 原始内容:We can see that the Rc<List> in a has an initial reference count of 1; then each time we call clone, the count goes up by 1. When c goes out of scope, the count goes down by 1.