ARC开启的情况下是否需要对GCD对象dispatch_release ?
2014-04-04 13:05
453 查看
If your deployment target is iOS 6.0 or Mac OS X 10.8 or later
ARC will manage your queue for you. You do not need to (and cannot) use dispatch_retain or dispatch_release if ARC is enabled.
在dealloc方法中应该加上
#if !OS_OBJECT_USE_OBJC //这个宏是在sdk6.0之后才有的,如果是之前的,则OS_OBJECT_USE_OBJC为0
dispatch_release(_barrierQueue);
#endif
当然了,也可以使用
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000 // 6.0sdk之前
dispatch_release(_barrierQueue);
#endif
这里的宏 __IPHONE_OS_VERSION_MIN_REQUIRED 就是我们在工程的设置项里设置的最低部署sdk版本
原因就是 对于最低sdk版本>=ios6.0来说,GCD对象已经纳入了ARC的管理范围,我们就不需要再手工调用 dispatch_release了,否则的话,在sdk<6.0的时候,即使我们开启了ARC,这个宏OS_OBJECT_USE_OBJC 也是没有的,也就是说这个时候,GCD对象还必须得自己管理
如果你部署的最低目标低于 iOS 6.0 or Mac OS X 10.8
你应该自己管理GCD对象,使用(dispatch_retain,dispatch_release),ARC并不会去管理它们
如果你部署的最低目标是 iOS 6.0 or Mac OS X 10.8 或者更高的
ARC已经能够管理GCD对象了,这时候,GCD对象就如同普通的OC对象一样,不应该使用dispatch_retain ordispatch_release
ARC will manage your queue for you. You do not need to (and cannot) use dispatch_retain or dispatch_release if ARC is enabled.
Starting in the iOS 6.0 SDK and the Mac OS X 10.8 SDK, every dispatch object (including a dispatch_queue_t) is also an Objective-C object. This is documented in the <os/object.h> header file: * By default, libSystem objects such as GCD and XPC objects are declared as * Objective-C types when building with an Objective-C compiler. This allows * them to participate in ARC, in RR management by the Blocks runtime and in * leaks checking by the static analyzer, and enables them to be added to Cocoa * collections. * * NOTE: this requires explicit cancellation of dispatch sources and xpc * connections whose handler blocks capture the source/connection object, * resp. ensuring that such captures do not form retain cycles (e.g. by * declaring the source as __weak). * * To opt-out of this default behavior, add -DOS_OBJECT_USE_OBJC=0 to your * compiler flags. * * This mode requires a platform with the modern Objective-C runtime, the * Objective-C GC compiler option to be disabled, and at least a Mac OS X 10.8 * or iOS 6.0 deployment target.
在dealloc方法中应该加上
#if !OS_OBJECT_USE_OBJC //这个宏是在sdk6.0之后才有的,如果是之前的,则OS_OBJECT_USE_OBJC为0
dispatch_release(_barrierQueue);
#endif
当然了,也可以使用
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000 // 6.0sdk之前
dispatch_release(_barrierQueue);
#endif
这里的宏 __IPHONE_OS_VERSION_MIN_REQUIRED 就是我们在工程的设置项里设置的最低部署sdk版本
原因就是 对于最低sdk版本>=ios6.0来说,GCD对象已经纳入了ARC的管理范围,我们就不需要再手工调用 dispatch_release了,否则的话,在sdk<6.0的时候,即使我们开启了ARC,这个宏OS_OBJECT_USE_OBJC 也是没有的,也就是说这个时候,GCD对象还必须得自己管理
如果你部署的最低目标低于 iOS 6.0 or Mac OS X 10.8
你应该自己管理GCD对象,使用(dispatch_retain,dispatch_release),ARC并不会去管理它们
如果你部署的最低目标是 iOS 6.0 or Mac OS X 10.8 或者更高的
ARC已经能够管理GCD对象了,这时候,GCD对象就如同普通的OC对象一样,不应该使用dispatch_retain ordispatch_release
相关文章推荐
- ARC开启的情况下是否需要对GCD对象dispatch_release ?
- ARC开启的情况下是否需要对GCD对象dispatch_release ?
- ARC开启的情况下是否需要对GCD对象dispatch_release ?
- iOS_ARC下需要release 的情况
- iOS-开启arc之后 NSNotificationCenter removeObserver 是否需要调用
- ARC写的代码 外部非ARC环境调用时到底是否需要release
- 开启arc之后 NSNotificationCenter removeObserver 是否需要调用?
- dispatch_release dispatch_retain 在 最低版兼容本为 6.0 or later 并且使用 ARC 的情况下 error
- 在非ARC项目中引用ARC对象,是否需要手动释放
- Java是如何判断对象是否需要回收的?
- close操作前要测试“文件对象”是否创建成功,如果多个流,需要分别去关闭
- as3对象销毁是否需要全部属性置null?
- Xcode中切换ARC/MRC,开启僵尸对象监控
- Azure Messaging-ServiceBus Messaging消息队列技术系列4-复杂对象消息是否需要支持序列化和消息持久化
- 怎样判断是否需要垃圾回收/对象是否存活
- oc经常提到的静态方法中返回的对象,是否需要进行reless操作。
- 非ARC情况下---用GCD实现单例模式
- 开启服务器,自动加载类是否需要开辟新的线程研究
- new创建一个对象,是否需要加括号?
- Tip10 创建对象时需要考虑是否实现比较器