简体   繁体   中英

Convert ARC to non-ARC

I've been developing a project with ARC technology for 10.6+ OS X 64-bit systems.

But now program has to support 32-bit 10.6 OS X system, but on 32-bit CPU ARC isn't working.

If i just turn ARC off and try to compile for 32bit it will cause a lot of errors.

What is the best way to convert program with ARC to program with manual memory management?

32-bit OS X 10.6 supports garbage collection. It is fairly simple to convert ARC code into GC code and vice-versa, eg there are a few cases where ARC needs an appropriate bridge cast while GC needs NSMakeCollectible and you can encapsulate these in macros.

If you use macros you can test for the compiler settings for ARC and GC and define the macros conditionally based on them - change the compiler settings and the code switches between ARC & GC.

Go through your code and retain / release objects as needed. You will need to look at each allocation of an object and see when you need to release it. You will also need to see what should be autoreleased and if/when you need to create your own autorelease pools and drain them. This is not something that can be automated if you want to do it right.

You might also think about doing both. Have a 32 bit target that supports doesn't use ARC and a 64 bit target that does. This will be lots of work, but probably not much more than the conversion. It WILL result in a much larger binary (probably 1.5 times as large depending on the ratio of code to resource items).

Check out the first answer to THIS SO question for a better explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM