Pankaj Gaikar Pankaj Gaikar - 3 months ago 27
iOS Question

Deallocate NSOperationQueue as soon as all operations in queue are finished

I want to deallocate NSOperationQueue when all the operations in progress are finished executing.
So far, I have coded below but as far as I know

waitUntilAllOperationsAreFinished
is async call and could not hold from my operationQueue getting nil.

- (void)deallocOperationQueue
{
[operationQueue waitUntilAllOperationsAreFinished];
operationQueue = nil;
}

Answer

Quoting Avi

You don't need to wait for all operations to finish. Just set operationQueue to nil when you're done with it. If the queue still has operations, nothing happens to them; they will still complete.

- (void)deallocOperationQueue
{
    operationQueue = nil;
}

I have tested the code and confirm that stated behaviour does happen.