memory management for dispatch queue &ARC

when reading apple's document on "Memory Management For Dispatch Queue", it's content as follows:

Even if you implement a garbage-collected application, you must still retain and release your dispatch queues and other dispatch objects. Grand Central Dispatch does not support the garbage collection model for reclaiming memory.

so is it need if i am using arc? After studying i found that:

If your deployment target is lower than iOS 6.0 or Mac OS X 10. 

You need to use dispatch_retain and dispatch_release on your queue. ARC does not manage them.

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 ordispatch_release if ARC is enabled. In fact, if you try to use it, it is a compiler error, just like what happen when you call release in earlier SDK.

To fix it, you may want to remove the dispatch_release, or use preprocessor:

/* header */
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
    #define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else                                         // iOS 5.X or earlier
    #define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

/* implementation */
#if NEEDS_DISPATCH_RETAIN_RELEASE
    dispatch_release(self.reachabilitySerialQueue);
#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值