Created
September 2, 2016 14:33
-
-
Save SiarheiFedartsou/78b3bd62090aff38385a927d7bac6893 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@class Foo; | |
@interface Foo2 : NSObject | |
@property (nonatomic, strong) Foo* foo; | |
- (void) releaseFoo; | |
@end | |
@interface Foo : NSObject | |
- (void) boo:(void(^)())block foo2:(Foo2*)foo2; | |
@end | |
@implementation Foo | |
- (void) boo:(void(^)())block foo2:(Foo2*)foo2 | |
{ | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
[foo2 releaseFoo]; | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
block(self); | |
}); | |
}); | |
} | |
@end | |
@implementation Foo2 | |
- (void) boo | |
{ | |
self.foo = [[Foo alloc] init]; | |
NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)(self.foo))); | |
__weak id wfoo = self.foo; | |
NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)(self.foo))); | |
[self.foo boo:^() { | |
NSLog(@"%@", wfoo); | |
NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)(self.foo))); | |
} foo2:self]; | |
} | |
- (void) releaseFoo | |
{ | |
NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)(self.foo))); | |
self.foo = nil; | |
} | |
@end | |
@interface AppDelegate () | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
Foo2* foo2 = [[Foo2 alloc] init]; | |
[foo2 boo]; | |
// Override point for customization after application launch. | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment