I have started using ARC (Automatic Referencing Count) in my project. I am using couple of third party libraries (which I have received from another team) which are still on non-ARC code. Is it safe to start using ARC even if external libraries do not conform to ARC?
Asked
Active
Viewed 148 times
1 Answers
3
Absolutely, it is safe to use ARC alongside the compiled non-ARC code. The compiler is smart enough to insert the retains and releases where necessary.
If other libraries are given to you as source code, you can disable ARC just for these files by adding the -fno-objc-arc
compiler flag, and it is going to work together with your ARC-enabled code. You can add this flag in the target's build phases.

jfuellert
- 550
- 4
- 10

Sergey Kalinichenko
- 714,442
- 84
- 1,110
- 1,523
-
1Just be sure that the library follows correct naming conventions. This can confused the compiler (i.e. if the word "new" appears but the function does not return a +1 object, then ARC will mistakenly release it, or so I read). – borrrden May 28 '13 at 03:11
-
@borrrden: What all precautions third party libraries should take to avoid unnecessary memory issues. Off late, I am seeing lot of crashes due to memory management issues. – Abhinav May 28 '13 at 03:14
-
@Abhinav Here is a good answer to the naming conventions related to ARC: [link](http://stackoverflow.com/a/15747674/335858). – Sergey Kalinichenko May 28 '13 at 03:19
-
If you have the source code of the third-party library, running the source code through the static analyzer (Product > Analyze) should point out places where the library doesn't follow the naming conventions. – rob mayoff May 28 '13 at 03:24
-
@robmayoff: I do not have source code of third party but just the compiled .a library file. Will that help? – Abhinav May 28 '13 at 03:51
-
No that will not help @Abhinav you will just have to trust them and use Instruments. – borrrden May 28 '13 at 04:02
-
Oh ok. 1 more question - Do I need implement dealloc in my code and set all the delegates to nil? – Abhinav May 28 '13 at 04:46
-
@Abhinav If a non-ARC object outlives its delegate, and that delegate is `assign` then yes. Otherwise, you risk a dangling pointer. – borrrden May 28 '13 at 09:41
-
@Abhinav If your delegates are declared `weak` in your ARC code, you do not need to set them to `nil` in the `dealloc`. – Sergey Kalinichenko May 28 '13 at 10:01