Can I authorize NSOperationQueue?

I have a piece of code that will only run once in the background when the application loads. I don't want to worry about NSOperationQueue * memory management, can I do autoreleasethis?

 NSOperationQueue *queue = [[NSOperationQueue alloc] init];
 NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(oneTimeTask) object:nil];
 [queue addOperation:op];
 [op release];
 [queue autorelease];

thank

+3
source share
1 answer

The short answer is no, if you want it to exist before the release of your application.
If you automatically release it, the queue object will be released (and therefore freed) in the next cycle of the event loop, which you probably don't need ...

+4
source

Source: https://habr.com/ru/post/1756532/


All Articles