Fire-and-forget controllers with blocks
Fire-and-forget controllers with blocks
- Subject: Fire-and-forget controllers with blocks
- From: Ben <email@hidden>
- Date: Fri, 20 May 2011 13:48:03 +0100
Hi list,
I've been tidying up a codebase which can now make use of block-based APIs and all is working quite nicely. However, in several places I have controllers which I want to setup and launch and then clean up when they're done. What I used to do was like this:
- (void)startImport
{
MyImportController *controller = [[MyImportController alloc] init];
[controller setCallbackTarget:self];
[controller start];
}
- (void)importDone:(MyImportController *)aController
{
// This method called from the controller
}
But what I've changed that to is this:
MyImportController *controller = nil;
CleanupBlock cleanup = ^{
[controller release];
// Other stuff
};
controller = [[MyImportController alloc] initWithCleanupBlock:[[cleanup copy] autorelease]];
[controller start];
// The controller calls cleanup() when it's done
It doesn't exhibit any problems that I can see, but the static analyzer complains that I'm leaking the controller object in the second example. Am I actually doing something wrong here? If not, is there a way to make analyzer recognise this?
- Ben
_______________________________________________
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