Reputation: 12444
I am trying to perform a method in a background thread using a NSOperationQueue like so:
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(method)
object:nil];
[queue addOperation:operation];
[queue release];
[operation release];
The problem is that, analyzer says that there is a leak that is stored into queue.
How can I fix this?
Upvotes: 0
Views: 1209
Reputation: 25917
Just wondering, what are you doing inside your method "method"? Are you using NSAutoreleasePool
? By the way, use this answer to help you out.
Upvotes: 1
Reputation: 1435
Calling [MyClass new] is the same as calling [[MyClass alloc] init], it return object with retainCount = 1. So, it should be released after.
Upvotes: 2
Reputation: 29767
Are you releasing operation
object? Try to add autorelease
keyword
NSInvocationOperation *operation = [[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(method)
object:nil] autorelease];
Upvotes: 1