4 ms·
If you use the Cocoa API with ObjC or Swift, you get Automatic Reference Counting (ARC), generated by the compiler. I guess with this you'd have to retain / re
by tempodox 3y ago
If you use the Cocoa API with ObjC or Swift, you get Automatic Reference Counting (ARC), generated by the compiler. I guess with this you'd have to retain / release your objects manually again?
- Klonoar 3y agoAuthor here. Nope, retain on create/etc and release on drop happens automatically.
- IshKebab 3y agoRust has ARC too so I very much doubt it.
- pjmlp 3y agoNope, someone has to manually type .clone() calls.
- IshKebab 3y agoThat's irrelevant (and barely different to having to type `=`). The salient point is that you don't need to manually call free/release.
- pjmlp 3y agoThat is more than relevant, otherwise we are comparing oranges to apples, pun intended. Automatic Reference Counting. Since = is the same as .clone() in character count?
- IshKebab 3y agoYes I'm aware that the A stands for Atomic in Rust, not Automatic. But it is still automatic because you do not need to increment and decrement the counter manually. > Since = is the same as .clone() in character count? Why does character count matter? I think you're getting a bit distracted from the point. Will you need to manually free/release objects? No you will not.
- deleted 3y ago[deleted]
- xanathar 3y agoNo. Rust has RAII so you can have retain on 'clone' operations and release on drops, just like the native Rc/Arc types do. This is, incidentally, how the servo bindings to core-foundation work (I prefer those bindings where there is overlap). Servo bindings: https://github.com/servo/core-foundation-rs https://github.com/servo/core-foundation-rs Other crates of interest on this topic: - https://crates.io/crates/objc https://crates.io/crates/objc - https://crates.io/crates/block https://crates.io/crates/block
- pjmlp 3y agoSomeone has to manually type .clone() calls.
- xanathar 3y agoIf you don't, the compiler tells you to, as per standard Rust semantics.
- pjmlp 3y agoAutomatic Reference Counting. Writing by hand isn't the same.
- xanathar 3y agoExcept that even Apple's ARC is not automatic - try passing the pointer to a GArray, or putting it on a malloc'ed linked list or any other data structure not implemented in Swift or ObjectiveC (provided that you compile objectiveC with the correct build flags). The point is: you can't leak, you can't end up keeping a reference without incrementing the refcount and you don't events have to worry about any of the refcounting as long as the code you write is sound according to Rust rules.
- pjmlp 3y agoMoving goalposts. We are speaking about the normal development experience, not corner cases or unsafe code.