Skip to content

Instantly share code, notes, and snippets.

@bjhomer
Created February 3, 2012 00:23
Show Gist options
  • Save bjhomer/1726708 to your computer and use it in GitHub Desktop.
Save bjhomer/1726708 to your computer and use it in GitHub Desktop.
Blocks are copied often
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
__block int x;
NSLog(@"Address of x outside of block: %p", &x);
^{
NSLog(@"Address of x in non-assigned block: %p", &x);
}();
void (^b)(void) = ^{
NSLog(@"Address of x in assigned block: %p", &x);
};
b();
}
return 0;
}
2012-02-02 17:23:19.010 blockcopying[39728:707] Address of x outside of block: 0x7fff5fbff918
2012-02-02 17:23:19.012 blockcopying[39728:707] Address of x in non-assigned block: 0x7fff5fbff918
2012-02-02 17:23:19.013 blockcopying[39728:707] Address of x in assigned block: 0x103000048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment