知识卡片
堆对象仍需追踪拥有链
堆上的值不会因离开当前栈帧就自然消失或永久存活,关键是哪个对象拥有它。Box中再包Box,最外层拥有者析构时会沿拥有关系释放内部值;移动Box可转移责任而不等于移动其堆内目标。共享环与显式泄漏另有例外,读生命周期应追踪拥有关系。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Lifetimes and the Heap · 查看原书依据
Lifetimes and the Heap The discussion so far has concentrated on the lifetimes of items on the stack, whether function parameters, local variables, or temporaries. But what about items on the heap? The key thing to realize about heap values is that every item has an owner (excepting special cases like the deliberate leaks described in the previous section).
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Lifetimes and the Heap》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u084-ch03-010)。
- 结论依据:原文在“Lifetimes and the Heap”附近的定义、例子或代码支撑本卡核心说明:堆上的值不会因离开当前栈帧就自然消失或永久存活,关键是哪个对象拥有它。边界按已读前提解释;示例未执行。
- 原始内容:Lifetimes and the Heap The discussion so far has concentrated on the lifetimes of items on the stack, whether function parameters, local variables, or temporaries. But what about items on the heap? The key thing to realize about heap values is that every item has an owner (excepting special cases like the deliberate leaks described in the previous section).