Alex Rivera | Logout

What is the correct way to release a GCD dispatch queue property?

Asked 2011-04-01T08:20:54.353
20

I'm using a dispatch_queue which is accessed through a property of its owner, like this:

@property (nonatomic, assign) dispatch_queue_t queue;

Note the assign keyword. The queue is used throughout the objects life and thus owned by the object. I release the queue when the owning object is deallocated:

-(void)dealloc
{
    dispatch_release(self.queue);
    self.queue = nil;
}

How do I properly release this? Would using retain/release work?

What happens if there is stuff pending/running on the queue while calling release?

Edit
Report

2 Answers

2

What happens if there is stuff pending/running on the queue while calling release?

It is safe. pending/running queue is retained from system. Calling dispatch_release just affects the retain count of the queue. See man page of dispatch_async or so forth.

answered 2011-04-01T09:52:12.480
2

setup your property like so:

@property (readwrite, strong, nonatomic) __attribute__((NSObject)) dispatch_queue_t queue;

Assign is implied and Strong will retain the queue telling ARC to treat it as an NSObject.

answered 2012-09-13T00:44:30.777

Your Answer