在Xcode4.5中禁用ARC(Automatic Referencing Counting)
来源:互联网 发布:阿里云如何关闭快照 编辑:程序博客网 时间:2024/05/22 04:25
最近升级了xcode4.5,用上了ios6的SDK。但用着用着发现一个比较烦的问题,以前很多代码提示错误,发现原来因为xcode启用了ARC,当ARC启用后会自动在代码中加入retain、release,原先需要手动添加的用来处理内存管理的引用计数的代码可以自动地由编译器完成了。虽然有很大的好处,但是对于以前代码中加的retain、release等会因此报错,解决办法很简单,禁用ARC即可,方法如下:
可以在 Build Setting => "Apple LLVM compiler 3.0-Auto Reference Counting“ => "Mugrate cide from MRR to ARC" 设置为 "MIGRATE code to ARC after building with PRECHECK" 这个就可以跳过烦人的预语法检查报错, 且自动转换成ARC。
禁用可以设置 Build Setting => "Apple LLVM compiler 3.0-Code Generation“ => “Objective-C automatic Reference Counting" 置为NO。
还可以设置 "Build Phases" => "Compile Sources" 中在禁用的源文件上加编译参数: -fno-objc-arc 。
基本的ARC使用规则
代码中不能使用retain, release, retain, autorelease
不重载dealloc(如果是释放对象内存以外的处理,是可以重载该函数的,但是不能调用[super dealloc])
不能使用NSAllocateObject, NSDeallocateObject
不能在C结构体中使用对象指针
id与void *间的如果cast时需要用特定的方法(__bridge关键字)
不能使用NSAutoReleasePool、而需要@autoreleasepool块
不能使用“new”开始的属性名称 (如果使用会有下面的编译错误”Property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects”)
使用ARC的好处
Objective-C的代码变得简单多了,因为我们不需要担心烦人的内存管理,担心内存泄露了
代码的总量变少了,看上去清爽了不少,也节省了劳动力
代码高速化,由于使用编译器管理引用计数,减少了低效代码的可能性
不好的地方
记住一堆新的ARC规则 — 关键字及特性等需要一定的学习周期
一些旧的代码,第三方代码使用的时候比较麻烦;修改代码需要工数,要么修改编译开关
- 在Xcode4.5中禁用ARC(Automatic Referencing Counting)
- 在Xcode4.5中禁用ARC(Automatic Referencing Counting)
- 在Xcode4.5中禁用ARC(Automatic Referencing Counting)
- xcode 编译器禁用 ARC (Automatic Referencing Counting)
- xcode 编译器禁用 ARC (Automatic Referencing Counting)
- arc automatic referencing counting
- 『IOS』xcode 编译器禁用 ARC (Automatic Referencing Counting)
- 如何禁用iOS 5 ARC 自动释放 (Automatic Reference Counting) ?
- Xcode 5 如何禁用某个文件ARC(Automatic Reference Counting)
- 如何在项目中开始使用ARC(Automatic Reference Counting)
- 了解Xcode 4.2中Automatic Reference Counting(ARC)
- ARC(Automatic Reference Counting )技术概述
- ARC(Automatic Reference Counting )技术概述
- ARC(Automatic Reference Counting )技术概述
- ARC(Automatic Reference Counting )技术概述
- ARC(Automatic Reference Counting )技术概述
- Automatic Reference Counting (ARC)
- Automatic Reference Counting (ARC)
- 【地球人..学习cocos2d-x】学习实践之逐步变强的HelloWorld(下集)
- SQL常用函数
- fatal error U1087: cannot have : and :: dependents for same target
- 存储过程 SET NOCOUNT ON
- Java Web层框架——JSF、Spring MVC、Stripes、Struts 2、Tapestry和Wicket他们各自的优点和缺点
- 在Xcode4.5中禁用ARC(Automatic Referencing Counting)
- U盘容量变小,重新分区
- C++常用库函数
- 简明Vim练级攻略
- 使用弹性盒布局来实现元素宽度与高度的自适应
- android记录和恢复ListView滚动的位置
- HDU 4320 Arcane Numbers 1
- ATL揭秘之“对象创建”
- RO IOCP开发心得系列(01):服务器程序防止Socket攻击的解决方案