Skip to main content

One doc tagged with "reference-counting"

View all tags

Rc<T>, the Reference Counted Smart Pointer

We've seen how Box enforces single ownership of heap-allocated data. But what happens when a single value needs to have multiple owners? For example, in a graph data structure, several edges might point to the same node, and that node shouldn't be cleaned up until all those edges are gone. For this, Rust provides the Rc smart pointer, which enables Reference Counting for shared ownership.