Is it dangerous to set off an autoreleased NSOperationQueue?
Posted
by Paperflyer
on Stack Overflow
See other posts from Stack Overflow
or by Paperflyer
Published on 2010-03-23T15:03:14Z
Indexed on
2010/03/23
18:33 UTC
Read the original article
Hit count: 379
I have a task that takes a rather long time and should run in the background. According to the documentation, this can be done using an NSOperationQueue
. However, I do not want to keep a class-global copy of the NSOperationQueue
since I really only use it for that one task. Hence, I just set it to autorelease and hope that it won't get released before the task is done. It works.
like this:
NSInvocationOperation *theTask = [NSInvocationOperation alloc];
theTask = [theTask initWithTarget:self
selector:@selector(doTask:)
object:nil];
NSOperationQueue *operationQueue = [[NSOperationQueue new] autorelease];
[operationQueue addOperation:theTask];
[theTask release];
I am kind of worried, though. Is this guaranteed to work? Or might operationQueue
get deallocated at some point and take theTask
with it?
© Stack Overflow or respective owner