简体   繁体   English

将ARC转换为非ARC

[英]Convert ARC to non-ARC

I've been developing a project with ARC technology for 10.6+ OS X 64-bit systems. 我一直在为10.6+ OS X 64位系统开发一个ARC技术项目。

But now program has to support 32-bit 10.6 OS X system, but on 32-bit CPU ARC isn't working. 但是现在程序必须支持32位10.6 OS X系统,但是32位CPU ARC无法正常工作。

If i just turn ARC off and try to compile for 32bit it will cause a lot of errors. 如果我只关闭ARC并尝试编译为32位,则会导致很多错误。

What is the best way to convert program with ARC to program with manual memory management? 使用ARC将程序转换为手动内存管理程序的最佳方法是什么?

32-bit OS X 10.6 supports garbage collection. 32位OS X 10.6支持垃圾回收。 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. 将ARC代码转换为GC代码非常简单,反之亦然,例如,有些情况下ARC需要适当的桥接转换,而GC需要NSMakeCollectible,您可以将它们封装在宏中。

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. 如果使用宏,则可以测试ARC和GC的编译器设置,并根据它们有条件地定义宏 - 更改编译器设置和ARC和GC之间的代码切换。

Go through your code and retain / release objects as needed. 浏览您的代码并根据需要retain / release对象。 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. 您还需要查看应该自动释放的内容以及是否/何时需要创建自己的autorelease pools并将其drain 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. 有一个32位目标支持不使用ARC和64位目标。 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). 它将导致更大的二进制文件(可能是代码与资源项比例的1.5倍)。

Check out the first answer to THIS SO question for a better explanation. 查看这个问题的第一个答案,以获得更好的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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