Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blocks: Release object in completion handler?

In my applicationDidFinishLaunching: method, I create an object and call an asynchronous method on it, like so:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    Foo *foo = [[Foo alloc] init];

    [foo asynchronousMethodWithCompletion:^{
        // Location A
    }];

    // Location B
}

If I do not use ARC, where do I have to put [foo release]? Inside the completion block (Location A) or right after the asynchronous method call (Location B)? Or doesn't it matter at all?

like image 594
tajmahal Avatar asked Nov 26 '12 00:11

tajmahal


1 Answers

You put [foo release] at Location B, like you normally would do if there was a regular method call instead of the block. The block will retain the object and release it after it is done.

like image 60
Davyd Geyl Avatar answered Nov 15 '22 14:11

Davyd Geyl