Recall & Review
beginner
What is a smart pointer in Rust?
A smart pointer is a data structure that not only holds a value but also has extra metadata and capabilities, like managing memory automatically.
Click to reveal answer
beginner
How does
Box<T> help with ownership?Box<T> stores data on the heap and gives ownership to a single owner, automatically freeing memory when it goes out of scope.Click to reveal answer
intermediate
What problem does
Rc<T> solve?Rc<T> allows multiple parts of code to share ownership of the same data by keeping a count of references, freeing memory only when the last owner is gone.Click to reveal answer
intermediate
Why use
RefCell<T> with Rc<T>?RefCell<T> allows mutable borrowing checked at runtime, so you can change data inside an Rc<T> even though Rc<T> itself is immutable.Click to reveal answer
advanced
What happens if you try to create a reference cycle with
Rc<T>?A reference cycle causes a memory leak because the reference count never reaches zero, so Rust can’t free the memory automatically.
Click to reveal answer
Which smart pointer in Rust allows multiple owners of the same data?
✗ Incorrect
Rc<T> enables multiple owners by reference counting.What does
Box<T> do with the data it owns?✗ Incorrect
Box<T> stores data on the heap and owns it exclusively.Which smart pointer allows mutation checked at runtime inside an immutable owner?
✗ Incorrect
RefCell<T> provides interior mutability with runtime borrow checking.What is a risk of using
Rc<T> without care?✗ Incorrect
Reference cycles prevent memory from being freed, causing leaks.
When does Rust free the memory owned by a
Box<T>?✗ Incorrect
Rust frees memory when the
Box<T> owner goes out of scope.Explain how ownership works with
Box<T> and why it is useful.Think about how Box stores data and what happens when it goes out of scope.
You got /4 concepts.
Describe the difference between
Rc<T> and RefCell<T> and when you might use them together.One manages how many owners exist, the other allows changing data inside an immutable owner.
You got /4 concepts.