https://www.jianshu.com/p/df0269e0d3c3
// __unsafe_unretained NSObject *boy1 = nil;
// {
// NSObject *boy2 = [[NSObject alloc] init];
// boy1 = boy2;
// NSLog(@"boy1 is %@", boy1);
// NSLog(@"boy2 is %@", boy2);
// }
// NSLog(@"boy1 is %@", boy1);
//
__weak NSObject *boy1 = nil;
{
NSObject *boy2 = [[NSObject alloc] init];
boy1 = boy2;
NSLog(@"boy1 is %@", boy1);
NSLog(@"boy2 is %@", boy2);
}
NSLog(@"boy1 is %@", boy1);
__weak 在引用计数为0时,会指向nil。但时是有性能开销的。
__unsafe_unretained 在引用计数为0时,会指向原地址。只要访问该地址,就是野指针访问,会闪退。