I see ARC as an acronym used every now and then, but for example in Rust it's "atomic reference counting", and in Swift or ObjC they call it "automatic reference counting". What exactly is the difference? As far as I know they seem to behave the same way.
The essence of atomic ref counting is to ensure that if two different instances of a shared_ptr (that are managing the same object) are accessed/modified, there will be no race condition. However, shared_ptr doesn't ensure thread safety, if two threads access the same shared_ptr object (and one of them is a write).
Without ARC or GC, you would need to manually add calls to retain and release, which would be Manual Reference Counting (MRC). In the case of the latter, human beings add the calls in the source code at development time, not at runtime or compile time.
ARC differs from tracing garbage collection in that there is no background process that deallocates the objects asynchronously at runtime. Unlike tracing garbage collection, ARC does not handle reference cycles automatically.
Swift uses Automatic Reference Counting (ARC) to track and manage your app's memory usage. In most cases, this means that memory management “just works” in Swift, and you don't need to think about memory management yourself.
This is actually... totally different.
On the Rust side, we have Arc
and Rc
which are reference counting pointers:
Rc
is the bare-bone reference-counting pointer: cloning it just increments a counter, and when the last Rc
pointing to a particular piece of data is dropped, the counter falls down to 0 and that piece of data is dropped too.Arc
is the atomic version of it, which means it is thread-safe and can be shared across threads (unlike Rc
).On the Swift side, ARC
refers to Automatic Reference Counting, Swift's Garbage Collection mechanism which as the name implies is automatic (and invisible in the code).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With