Blocks: Free an object in a completion handler?

In my applicationDidFinishLaunching: method applicationDidFinishLaunching: I create an object and call the asynchronous method on it, for example:

 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { Foo *foo = [[Foo alloc] init]; [foo asynchronousMethodWithCompletion:^{ // Location A }]; // Location B } 

If I do not use ARC, where do I need to put [foo release] ? Inside the termination block (location A) or immediately after calling the asynchronous method (location B)? Or does it not matter at all?

+7
source share
1 answer

You put [foo release] at location B, as you would if a regular method call were made instead of a block. The block will save the object and release it after its completion.

+6
source

All Articles