Skip to content

Instantly share code, notes, and snippets.

@n-b
Last active December 13, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n-b/4973808 to your computer and use it in GitHub Desktop.
Save n-b/4973808 to your computer and use it in GitHub Desktop.
Test retain cycle with block parameters
#import <Foundation/Foundation.h>
@interface Foo : NSObject
@end
@implementation Foo
- (void) setBar:(void(^)(void))block {}
- (void) doBaz:(void(^)(void))block{}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Foo * f = [Foo new];
[f doBaz:^() { NSLog(@"%@",f); }]; // No warning here
[f setBar:^() { NSLog(@"%@",f); }]; // Clang outputs a retain-cycle warning here
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment