知识卡片

普通读书笔记卡 · 10504.g.1 · 生成模型:未记录

资源沿所有权树释放

理解等级:中级

变量拥有它绑定的值,结构体和元组拥有字段,数组和向量拥有元素。每条普通所有权边把销毁责任交给父节点。例如,离开 Vec 的作用域会销毁向量及元素,每人的 String 又负责释放文本缓冲区。Box 也沿同样的边销毁堆上的 T 并释放其空间。读代码时沿这条链找根,就能判断归属于该根的资源何时释放。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第03章《Ownership and Moves》|所有权树与随作用域释放,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch03.xhtml#ownership-1` - 结论依据:原文逐层跟踪 composers、向量、Person、String 的归属,并用 Box 说明独立堆分配的销毁责任。 - 原始内容:It follows that the owners and their owned values form trees: your owner is your parent, and the values you own are your children.