Reputation: 303
I have a class A which uses ARC and other classes B and C which don't. If A contains class B objects and B contains class C objects then how does ARC work and what happens when memory management is not handled properly in class B and C?
Upvotes: 2
Views: 213
Reputation: 437632
I agree with Mike and Martin, that the integration of non-ARC objects in an ARC class generally takes place seamlessly (assuming you've added the -fno-objc-arc
compile flag to those .m files that are not ARC or are in a library that was compiled with manual reference counting).
One caveat is that ARC relies upon code conforming with the method naming rules outlined in the Basic Memory Management Rules. Thus, your non-ARC code must comply with these method naming rules or else ARC may not handle the resulting objects correctly. This is not an issue if the non-ARC code follows long-standing method naming conventions (that methods starting with alloc
, new
, copy
, and mutableCopy
will return +1 objects, and otherwise objects returned from methods will be autorelease
objects), so it is generally not an issue. But if your non-ARC code does not follow this method naming convention, but it may become a memory management stumbling block when integrating this non-ARC code with your ARC class.
If the non-ARC code does not comply with these naming conventions, you either have to rename the methods, correct the memory management of the code to correspond to the method name, or supply hints for the compiler where the code does not comply with these method naming rules (e.g. NS_RETURNS_RETAINED
or NS_RETURNS_NOT_RETAINED
).
Upvotes: 2
Reputation: 801
What ARC does is it looks at your code and makes assumptions where your objects should be released, autorelease etc. At the compile time all the retain, release, retainCount, autorelease, or dealloc methods will be added to your code. This makes your non-arc code completely compatible with your arc code.
As for the improper memory management, try to use static analyzer on build to get as much errors as you can.
Hope this helps, cheers!
Upvotes: 1