Skip to content

Instantly share code, notes, and snippets.

@torsten
Created July 9, 2012 16:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save torsten/3077554 to your computer and use it in GitHub Desktop.
Retain cylcle warnings
// Illustrates that not all causes of retain cycles are detected by clang. Compile with:
// clang -fobjc-arc -Wall -framework Foundation test-cycle-warnings.m && ./a.out
#import <Foundation/Foundation.h>
@interface Foo : NSObject
typedef void (^Block)();
@property (readwrite, copy) Block asd;
@end
@implementation Foo
@synthesize asd = _asd;
@end
int main (int argc, char const *argv[])
{
Foo *self = [[Foo alloc] init];
self.asd = ^()
{
// Causes no retain cycle warning: (FAIL)
Block b = self.asd;
// Causes a retain cycle warning:
[self description];
};
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment