diff --git a/projects/ref_cycle_demo/src/main.rs b/projects/ref_cycle_demo/src/main.rs index 37e3c7f..f3f96e5 100644 --- a/projects/ref_cycle_demo/src/main.rs +++ b/projects/ref_cycle_demo/src/main.rs @@ -20,7 +20,7 @@ impl List { fn main() { let a = Rc::new( Cons( - 5, + 5, RefCell::new(Rc::new(Nil)) ) ); @@ -30,7 +30,7 @@ fn main() { let b = Rc::new( Cons( - 10, + 10, RefCell::new(Rc::clone(&a)) ) ); diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 5eba87a..3563cb1 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -107,7 +107,7 @@ - [使用 `Drop` 特质在内存清理时运行代码](smart_pointers/drop-t.md) - [引用有计数的灵巧指针 `Rc`](smart_pointers/rc-t.md) - [`RefCell` 与内部可变性模式](smart_pointers/refcell-t.md) - - [引用环会泄露内存](smart_pointers/ref-cycles.md) + - [引用循环会泄露内存](smart_pointers/ref-cycles.md) - [无惧并发](Ch16_Fearless_Concurrency.md) - [使用线程同步运行代码](concurrency/threads.md) diff --git a/src/smart_pointers/ref-cycles.md b/src/smart_pointers/ref-cycles.md index 0696131..05c2d82 100644 --- a/src/smart_pointers/ref-cycles.md +++ b/src/smart_pointers/ref-cycles.md @@ -1,4 +1,4 @@ -# 引用循环可能会泄露内存 +# 引用循环会泄露内存 **Reference Cycles Can Leak Memory** @@ -17,7 +17,7 @@ Rust 的内存安全保证,使得意外创建出从未清理过的内存(称 文件名:`src/main.rs` ```rust -{{#include ../projects/ref_cycle_demo/src/main.rs::18}} +{{#include ../../projects/ref_cycle_demo/src/main.rs::18}} ``` *清单 15-25:包含 `RefCell` 的构造列表定义,因此我们可以修改 `Cons` 变种指向的内容* @@ -30,7 +30,7 @@ Rust 的内存安全保证,使得意外创建出从未清理过的内存(称 文件名:`src/main.rs` ```rust -{{#include ../projects/ref_cycle_demo/src/main.rs:20:}} +{{#include ../../projects/ref_cycle_demo/src/main.rs:20:}} ``` *清单 15-26:创建出相互指向的两个 `List` 的循环引用* @@ -215,7 +215,7 @@ children: RefCell { value: [] } }] } }) 文件名:`src/main.rs` ```rust -{{#include ../projects/tree_demo/src/main.rs:11:}} +{{#include ../../projects/tree_demo/src/main.rs:11:}} ``` *清单 15-29:在内层作用域中创建 `branch` 并检查强引用和弱引用计数*