I have an NSOperation that I wanted to bracket with an NSAutoreleasePool, like this:
- (void) start {
opPool = [[NSAutoreleasePool alloc] init];
if (self.isCancelled) {
[self finish];
}
''' more code ...
}
and
- (void) finish {
[opPool release];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:nil];
... more finish code here ...
self.state = LSOperationStateFinished;
}
opPool is an iVar.
The operation works without the NSAutoreleasePool allocation and release. But it crashes with it implemented as shown.
I put a break point in both methods to see what the description of [NSThread currentThread] is. It is the same inside both methods.
My understanding from the documentation on Autorelease Pools is that I should set one up for background threads that is separate from the main thread. This was how I wanted to do it, but apparently this is not the right way?
Am I doing something fundamentally wrong? What should I do to satisfy the documented requirement?