I have a piece of code which will run only once in the background when the app loads. I don开发者_开发知识库't want to worry about memory management of the NSOperationQueue *, can I autorelease
it?
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(oneTimeTask) object:nil];
[queue addOperation:op];
[op release];
[queue autorelease];
Thanks
Short answer is no, if you want it to exist till your app exits.
If you auto-release it, the queue object will be released (and so deallocated) at the next cycle of the event loop, which you probably don't want...
精彩评论