This is a general question about autorelease, Cocoa threads and NSOperationQueue.
I am using NSOperationQueue to perform certain API calls, parse the result and return it to the main thread. NSOperationQueue performs these operations on new threads. If I understand correctly every time a new thread is started there is an automatic autorelease pool created around this thread which is released when the thread is finished.
Here is the case that is giving me trouble. I pass an allocated NSArray to NSOperationQueue. During the operation the array gets populated with a bunch of autoreleased objects that get created. Then the array is returned back to the main thread.
Since the autoreleased objects were created on the thread would they be deallocated? As I understand they should not since their ref count is 1, after they were added to NSArray.
Who now owns releasing these objects? Did autorelease magically passed responsibility to the main thread autorelease pool.
Would any of this be different if I was creating threads myself rather than using NSOperationQueue?
Thank you!
NSOperation
s need to have aNSAutoReleasePool
created for them.