解决block循环引用--ARC
2020-04-17 本文已影响0人
大鹅ne
🌟用__weak,__unsafe_unretained解决
__weak typeof(self) weakSelf = self;
self.block = ^{
__strong typeof(weakSelf) myself = weakSelf;
NSLog(@"age is %d", myself->_age);
};
__unsafe_unretained typeof(self) weakSelf = self;
self.block = ^{
NSLog(@"age is %d", weakSelf.age);
};
Screen Shot 2020-04-17 at 5.51.27 PM.png
🌟用__block解决(必须要调用block)
__block id weakSelf = self;
self.block = ^{
printf("%p",weakSelf);
weakSelf = nil;
};
self.block();
Screen Shot 2020-04-17 at 5.53.20 PM.png