Does ARC do anything extra at run time? The comments on this answer say "ARC bumps reference counts at run-time and releases only when they reach zero". Is this true? If so why is this done if the release calls are added at compile-time?
2 Answers
ARC follows a similar, if not same, mechanism as C++'s std::shared_ptr, which uses a reference count to see, if that when the object goes out of scope, that the exit time function should be called; in the case of Obj-C, that call would go to release.
The release calls that are added by the compiler to manage how the reference counts are decremented; the way the clang mechanism does it is very cleaver and saves you the trouble of checking whether or not you have balanced calls to release for ever call to every method that increments your reference count.
So regarding your original question, ARC should not incur additional performance costs in your runtime application.
If you suspect that your app is suffering memory problems, you should profile your app in Instruments and see where time is being spent.
Memory optimization is a whole different ball of wax, which thankfully there are solutions. So, if you are having a highly threaded application have problems with concurrent memory allocation, you can look at an open-source library like Intel's Thread Building Blocks, which comes with an excellent memory manager, though be warned, it's designed for C/C++.
By the way, for a detailed explanation of ARC, read this page: http://clang.llvm.org/docs/AutomaticReferenceCounting.html

- 755
- 3
- 13
ARC isn't free - it will increase and decrease reference counts, and dealloc objects when the reference count is 0.
Compared to manual retain / release, ARC will be correct, it may call retain / release less often because it often knows when a retain / release pair cancels each other out, and the retain / release is faster because it doesn't call Objective-C method calls (in Objective-C, you can override retain / release; with ARC you can't).

- 51,477
- 5
- 75
- 98
-
Why does it increase and decrease reference counts at run time instead of at compile time. – oneofone Aug 14 '16 at 23:31