Challenge 2: Tracking Rc's Reference Count — Possible Solution ==================================================================== use std::rc::Rc; fn main() { let a = Rc::new(String::from("shared")); println!("count after creation: {}", Rc::strong_count(&a)); // 1 let b = Rc::clone(&a); println!("count after first clone: {}", Rc::strong_count(&a)); // 2 let c = Rc::clone(&a); println!("count after second clone: {}", Rc::strong_count(&a)); // 3 drop(c); println!("count after dropping c: {}", Rc::strong_count(&a)); // 2 } WHY THIS WORKS AS AN ANSWER ------------------------------ Each Rc::clone(&a) call increments the SAME shared reference count by one — it does NOT create a new, independent copy of the underlying String data, exactly this chapter's point that Rc::clone is cheap specifically because it only touches a counter, not the actual heap data. Rc::strong_count(&a) can be called through ANY of the Rc handles (a, b, or c) at any point and returns the SAME number, since all of them point at the identical shared count — there is only one count being tracked, not one per handle. drop(c) explicitly ends c's ownership early rather than waiting for the end of main's scope — this immediately decrements the shared count from 3 back to 2, demonstrating concretely that the count genuinely reflects how many Rc handles are CURRENTLY alive at any given moment, not just a static total of how many clones were ever made. The underlying String itself is still NOT dropped at this point, since two owners (a and b) remain — it would only actually be freed once the count reaches zero, which per this chapter's explanation happens when the LAST remaining Rc handle is dropped.