Are blocks passed by reference or by value from one call on stack to another?

Viewed 974

When I pass block to other method (not to heap with Block_copy or @property(copy)), is it copied or is it passed by reference?

I mean:

- (void)processBlock:(MyBlockType)block param:(int)param {

}

- (void)someMethod {
    int b1 = 10;
    int a1 = 9;
    [self processBlock:^int(int number, id object) {
        NSLog(@"block");
        return 1 + a1;
    } param:b1];
}

It is NSStackBlock - because it captures "a" variable, so it is allocated on stack. When I pass them to the other method is it copied and stored on processBlock's section of stack, or just passed by reference?

like that:

copyOf myBlock
copyOf b1
processBlock
..........
..other variables..
a1
b1
myBlock
someMethod
..........

Or Like that:

*myBlock (jast a pointer)
copyOf b1
processBlock
..........
..other variables..
a1
b1
myBlock
someMethod
..........
2 Answers
Related