Re: NSOperationQueue
Re: NSOperationQueue
- Subject: Re: NSOperationQueue
- From: Quincey Morris <email@hidden>
- Date: Sat, 13 Sep 2008 09:52:35 -0700
Your code is crashing because you're doing it wrong:
On Sep 13, 2008, at 05:05, John Love wrote:
- (void) calculateWorksheet:(id)data {
int row;
for (row=1; row < 500; row++) {
// long calculation here
}
}
- (void) startQueue {
NSLog(@"start queue"); // I see this in the debugger
opData = @"not used data";
theQueue = [[NSOperationQueue alloc] init];
theOp = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(calculateWorksheet:)
object:opData];
[theQueue addOperation:theOp];
}
- (void) stopQueue {
NSLog(@"stop queue"); // .. but I do not see this
[theQueue cancelAllOperations];
// [theQueue release]; // done by [theOp release]
[opData release];
[theOp release];
}
Cancelling a NSOperation (including a NSInvocationOperation) doesn't
stop it. The operation itself must detect that it was cancelled, then
clean up and exit. So what this code effectively does is to release
'theOp' while it's still running. It's not surprising you're getting a
crash as a result.
Also, it's not clear why you think '[theOp release]' releases
'theQueue' too. Normally, you'd expect the queue to persist for the
life of your application, while the operations are created, added to
the queue and destroyed as needed. There's nothing absolutely wrong
with creating a new queue for every operation, I guess, but you are
going to have to release the queue when the operation using it is
finished.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden