Rust theorytheory 0/50 · 0%
Memory · medium

25. Smart Pointers: Box, Rc, RefCell

Heap allocation and shared ownership.

`Box<T>` heap-allocates and enables recursive types. `Rc<T>` gives shared ownership by reference counting in single-threaded code, with `Weak` breaking cycles. `RefCell<T>` moves borrow checking to runtime, panicking on violations; Rc<RefCell<T>> is the classic shared-mutable pattern.

Check your understanding

  1. 1. Which allows multiple owners?

  2. 2. RefCell enforces borrows…