Reputation: 35925
I have an application I am updating to the latest version of Xcode and am being hit by multiple errors related to Automatic Reference Counting (ARC).
The errors call me to pull calls to e.g., autorelease
and tweaking other code I have written that deals with memory management.
The Clang documentation reads:
[ARC] does not provide a cycle collector; users must explicitly manage lifetime instead.
... which makes me very nervous. I've been bitten by Objective-C memory management issues in the past, and slaved over justifying every retain
, release
and autorelease
in my code.
Now ARC is calling me to take a leap of faith in altering my memory management semantics. What do I need to know to establish faith in ARC's memory management?
Upvotes: 2
Views: 216
Reputation: 104698
Naming Conventions. Fix every static analyzer issue and make sure your naming is clear and matches the conventions - this now serves as communication to the compiler. Now, this really is not necessary, but it is good to remove all the compiler and checker warnings, test, ensure your are happy with the naming, then convert. That also means increasing your warning levels and fixing the issues.
Avoid Attributes Details here: Deep copy of dictionaries gives Analyze error in Xcode 4.2
The examples in "Avoid Attributes" demonstrate the importance of type safety, descriptive method names, and ensuring you include what you use in a translation and use strict selector matching. opt: -Wstrict-selector-match
. Type safety will also come up when you perform unsafe conversions -- chances are, you will need to introduce type safety via special casting in some parts of your program.
Dangling References to Unmanaged types. Seen here: Assigning an existing CGColor to a CGColor property works in iOS Simulator, not iOS device. Why?
[ARC] does not provide a cycle collector; users must explicitly manage lifetime instead.
This refers to strong cyclic references (e.g. codependent objects). These would exist in your old program. Instruments can help you detect them.
After you have concluded the conversion, be prepared to test several OS versions.
Good Luck!
Extras:
What are the advantages and disadvantages of using ARC?
Upvotes: 7