TL; DR:dispatch_queue_t
現在是Objective C對象,可以使用ARC進行管理。
我還沒有測試過這種情況,但使用iOS 7 SDK和Xcode 5,dispatch_queue_t
是一種對象類型。我正在宣佈一個隊列屬性爲
@property (nonatomic, strong) dispatch_queue_t syncQueue;
編譯器很高興,一切都按預期工作。我明確知道,這在iOS 4或5(預ARC爲retain
而不是strong
)中不起作用。我挖成定義dispatch_queue_t
,發現這個:
/*!
* @typedef dispatch_queue_t
*
* @abstract
* Dispatch queues invoke blocks submitted to them serially in FIFO order. A
* queue will only invoke one block at a time, but independent queues may each
* invoke their blocks concurrently with respect to each other.
*
* @discussion
* Dispatch queues are lightweight objects to which blocks may be submitted.
* The system manages a pool of threads which process dispatch queues and
* invoke blocks submitted to them.
*
* Conceptually a dispatch queue may have its own thread of execution, and
* interaction between queues is highly asynchronous.
*
* Dispatch queues are reference counted via calls to dispatch_retain() and
* dispatch_release(). Pending blocks submitted to a queue also hold a
* reference to the queue until they have finished. Once all references to a
* queue have been released, the queue will be deallocated by the system.
*/
DISPATCH_DECL(dispatch_queue);
通過的那個聲音,它不應該工作,所以我檢查的DISPATCH_DECL
定義和發現這一點,這說明了一切:
/*
* By default, dispatch 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.
* See <os/object.h> for details.
*/
@JimThio:[Grand Central Dispatch](http://developer.apple.com/library/ios/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html) – 2012-05-18 06:16:11
這已不再是真實的山獅 - 請參閱/usr/include/os/object.h。 GCD和XPC「對象」(任何你可能明確發佈的)現在的行爲已經足夠像他們可以參與ARC的ObjC對象。 – jkh 2012-08-28 00:13:04
@jkh是否也包含iOS平臺? – Ankur 2013-01-06 05:29:59