mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2025-02-26 11:21:05 +08:00
Updated 'src/smart_pointers/ref-cycles.md'.
This commit is contained in:
parent
ba3ab0b6d3
commit
c3b2827f9b
@ -107,7 +107,7 @@
|
||||
- [使用 `Drop` 特质在内存清理时运行代码](smart_pointers/drop-t.md)
|
||||
- [引用有计数的灵巧指针 `Rc<T>`](smart_pointers/rc-t.md)
|
||||
- [`RefCell<T>` 与内部可变性模式](smart_pointers/refcell-t.md)
|
||||
- [引用环会泄露内存](smart_pointers/ref-cycles.md)
|
||||
- [引用循环会泄露内存](smart_pointers/ref-cycles.md)
|
||||
|
||||
- [无惧并发](Ch16_Fearless_Concurrency.md)
|
||||
- [使用线程同步运行代码](concurrency/threads.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<T>` 的构造列表定义,因此我们可以修改 `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` 并检查强引用和弱引用计数*
|
||||
|
Loading…
Reference in New Issue
Block a user