知识卡片
静态跟踪资源寿命
Rust 在编译时记录值的创建和移动、当前所有者、变量是否仍有值,以及引用能在哪里使用。资源随当前所有者的销毁释放,借用必须在资源仍然有效时使用。例如,一个字符串移入新变量以后,旧变量就不能再访问原缓冲区,缓冲区由新所有者负责销毁。这个约束也让同步类型可以在安全 Rust 中防止数据竞争。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Ownership and Moves 用编译期规则兼顾释放时机与内存安全 · 查看原书依据
The compiler also analyzes references to those values to prevent the use of dangling pointers.
参考来源
- 位置:《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`
- 结论依据:原文把所有权跟踪和引用检查分别连接到避免使用未初始化值、重复释放和悬垂指针,并指出相同规则支撑数据竞争防护。
- 原始内容:The compiler also analyzes references to those values to prevent the use of dangling pointers.