Reputation: 1568
This is probably an easy one, but I did a couple quick searches and couldn't find the answer. Do I have to retain an NSOperationQueue
(by using property etc) to avoid having it be released after a method finishes execution. For example:
- (void)doOperation:(NSOperation *)someOperation {
NSOperationQueue *queue = [[NSOperationQueue alloc] init]
[queue addOperation:someOperation];
}
I know that the operation will be retained by the queue while it is executing, but will the queue get released by arc as it has no explicit references outside the scope of this method?
Upvotes: 4
Views: 547
Reputation: 535566
The documentation says:
Operation queues retain operations until they're finished, and queues themselves are retained until all operations are finished.
Thus, the common pattern
[[[NSOperationQueue alloc] init] addOperation:op];
or, in Swift
OperationQueue().addOperation(op)
is safe.
Upvotes: 3