Rust: Weak References

Rust: Weak References

4.588 Lượt nghe
Rust: Weak References
#rust #weak #cycles It’s possible to allocate memory in Rust that never get’s cleaned up. This is a memory leak. Items that refer to each other create cycles. This means that neither item that references the other will ever reach a reference count of 0, and, therefore, never be dropped. 0:00 Intro 0:33 Creating a Reference Cycle 7:21 Preventing Reference Cycles: Turning an Rc into a Weak 8:36 Reviewing Trees 10:29 Creating a Tree Data Structure: a Node with Child Nodes 12:22 Adding a Reference from a Child to Its Parent 16:49 Visualizing Changes to strong_count and weak_count 19:11 Outro Links Reference Cycles Can Leak Memory Chapter 15 Section 16 https://doc.rust-lang.org/book/ch15-06-reference-cycles.html