Adding ARC support to third-party framework

Hello,


I am working with a legacy codebase which cannot be converted to use automatic reference counting. Recently, we were asked to add the official dropbox sdk to the project, which I installed via cocoapods. However, this sdk was built with ARC and I'm getting a ton of reports in the leak profiler when the sdk is used. I know you can enable ARC for certain files by adding the -fobjc-arc flag in the build phases's Compile Sources section, but the source files associated with the dropbox sdk do not show up there. Does anyone where I need to go to add ARC to files that are handled by cocoapods?

In principle, nothing stops you using library built with ARC with your own code that uses manual memory ref-counting (MMR). If you properly handle the ownership of objects used by the SDK, there should be no leaks (apart from bugs in the SDK!).


It's worth putting some effort into trying to work out why the leaks are happening. For example, if you create an object in an SDK class using alloc/init, it's returned with a +1 ownership count, and your code must release it when your reference goes out of scope. In other words, it should make no difference to your code whether the SDK uses ARC or not.


You can also look at the old transition guide:


https://developer.apple.com/library/archive/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html


for guidance on specific issues, if you're being affected by an odd case.


Finally, you can use the Allocations tool in Instruments to capture and examine the allocation history of leaked objects, to try to find out where unmatched retains are coming from. (You can try the memory graph debugger in Xcode, but it has a reputation for being unreliable.)

Thanks for responding. Could you clarify something for me? I was under the impression that because the SDK was created without ARC, it would be missing release calls in its internal methods. Then, because I'm using a project that doesn't have ARC, those release calls never get injected and any init/copy calls within the sdk could become memory leaks.

Adding ARC support to third-party framework
 
 
Q