I have read this in "Block Programming Topics"
"Each invocation of the block provides a new copy of that variable. These variables can in turn be used as const or by-reference variables in blocks enclosed within the block."
So, I have tested following code.
// Employee.h
@interface Employee : NSObject
@end
// Employee.m
@implement Employee
@end
// main.m
int main() {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
Employee* john = [[Employee alloc] init] autorelease];
void (^blockTest)(void) = ^ {
NSLog(@"john = %@", john);
NSLog(@"john retain count = %ld", [john retainCount]);
};
blockTest();
[pool drain];
return 0;
}
I have expected "John" retain count will be 2 when blockTest is executed, but result is 1.
Can anyone help me to understand it?