mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 21:31:17 -06:00
Merge pull request #414 from ilabdsf/patch-1
Explain why weak pointers are needed
This commit is contained in:
@@ -61,9 +61,9 @@ Same as Rc, but doesn't count towards the strong ref count. When you do this, th
|
|||||||
strong ref count goes down and the weak count goes up.
|
strong ref count goes down and the weak count goes up.
|
||||||
|
|
||||||
Data gets cleaned up when the strong count is 0, no matter what the weak count is.
|
Data gets cleaned up when the strong count is 0, no matter what the weak count is.
|
||||||
|
However, Rc structure is kept until weak reference count also goes to zero, so weak pointers do not become dangling pointers.
|
||||||
Why is the weak count needed then????
|
At this point, attempt to upgrade Weak pointer will result into None.
|
||||||
|
Only when weak reference counter also reduces to zero, Rc structure is freed.
|
||||||
|
|
||||||
## `RefCell<T>`
|
## `RefCell<T>`
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user