I'm looking to learn about how Rust's refcounting memory management works (and how it differs from how, e.g. Objective-C or Swift's runtime-based reference counting works), mostly for personal edification. Can anyone point me to any good resources?
I'm looking to learn about how Rust's refcounting memory management works (and how it differs from how, e.g. Objective-C or Swift's runtime-based reference counting works), mostly for personal edification. Can anyone point me to any good resources?
I've written a regex library, CSV parser, command line arg parser, elastic tabs and quickcheck in Rust. Behold:
$ find ./ -type f -name '*.rs' -print0 | xargs -0 grep Rc
$
I've definitely reached for it a few times as an escape hatch, but I've always ended up finding a cleaner approach to persist without it.Of course, there are plenty of legitimate uses of refcounting. I just haven't hit them yet. :-)
Fixed nonetheless. Do'h.
You can find documentation on these types here: http://doc.rust-lang.org/guide-pointers.html
This is different from shared_ptr in C++ which is always atomic and LLVM has to try hard (in clang, no idea what GCC does) to eliminate some redundant ref-counts.
Oh and since Rc is affine, you only ref-count when you call .clone() on it or you let it fall out of scope.
Most of the time you can pass a reference to the contents, or, if you need to sometimes clone it, a reference to the Rc handle, avoiding ref-counting costs.