memory management for dispatch queue &ARC

来源:互联网 发布:pp助手网络连接失败 编辑:程序博客网 时间:2024/06/03 13:34

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