• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fire-and-forget controllers with blocks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Fire-and-forget controllers with blocks
      • From: Kyle Sluder <email@hidden>
    • Re: Fire-and-forget controllers with blocks
      • From: Dave Zarzycki <email@hidden>
  • Prev by Date: Re: Why RunLoop?
  • Next by Date: Re: Fire-and-forget controllers with blocks
  • Previous by thread: Re: Cocoa Touch (iPhone/iPad): List of notifications?
  • Next by thread: Re: Fire-and-forget controllers with blocks
  • Index(es):
    • Date
    • Thread