3 ms·
Not so sure, does Objective-C have a single ownership model and move semantics? As far as I know it doesn't, which would make it pretty different.
by YorickPeterse 5y ago
Not so sure, does Objective-C have a single ownership model and move semantics? As far as I know it doesn't, which would make it pretty different.
- flohofwoe 5y agoObjective-C (and I guess Swift too?) has ARC (see link in grandparent) which attempts to statically track the lifetime of objects at compile time. This essentially results in a "move operation" if the compiler detects that the original reference isn't used anymore after the assigment. It's basically halfway between C++'s shared_ptr-vs-unique_ptr approach, and Rust's lifetime and ownership tracking.
- pjmlp 5y agoARC was a marketing gimmick, after the failure of getting a conservative GC to properly work with the underlying C semantics alongside the mix of frameworks compiled in different modes. The only thing it does is to automate the retain/release calls of Cocoa classes, or classes that offer similar API. It doesn't apply to any other C like types from Objective-C, and basically the generated machine code is hardly different than when devs keep doing those calls by hand. Yes there is some potential for the compiler to remove needless set of retain/release pairs for short lived objects, it doesn't happen all the time though. Swift, also despite the ARC marketing, made the sensible choice to go with ARC, because one of the key designs was interoperability with Objective-C runtime. As shown by RCW/CCW runtime used by .NET for interoperability with COM's AddRef/Release, there is a lot of more machinery required to have a tracing GC cooperate with RC scheme, so it was understandable this route wasn't chosen for Swift. As some papers prove, current performance isn't that great, which is also Swift 5.5 is bringing a more aggressive optimization, which is turned off by default. Check WWDC 2021, "ARC in Swift: Basics and beyond".