This appears to be working from all points of view (thank you, Instruments!):
MyMandelbrotOperation* op =
[[MyMandelbrotOperation alloc] initWithSize:self.bounds.size
center:center zoom:1];
__block __weak id observer = [[NSNotificationCenter defaultCenter]
addObserverForName:@"MyMandelbrotOperationFinished"
object:op queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
MyMandelbrotOperation* op2 = note.object;
CGContextRef context = [op2 bitmapContext];
if (self->bitmapContext)
CGContextRelease(self->bitmapContext);
self->bitmapContext = (CGContextRef) context;
CGContextRetain(self->bitmapContext);
[self setNeedsDisplay];
[[NSNotificationCenter defaultCenter] removeObserver:observer
name:@"MyMandelbrotOperationFinished" object:op2];
}];
[self.queue addOperation:op];
This is delightful. I'm not leaking self, my operations are being dealloced in
good order, I'm successfully registering and deregistering, I'm trampolining to
the main thread without writing a trampoline method, I'm avoiding the nightmare
of storing my observers in an instance variable, op and op2 are the same object
- everything about it seems to be okay. My questions are:
* Is this really an okay way to talk?
* Why was I crashing until I said __block?
m.
--
matt neuburg, phd = [email protected], http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]