http://www.reibang.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 在引用計(jì)數(shù)為0時(shí)坡贺,會(huì)指向nil疙挺。但時(shí)是有性能開(kāi)銷的问词。
__unsafe_unretained 在引用計(jì)數(shù)為0時(shí)础浮,會(huì)指向原地址。只要訪問(wèn)該地址沽瞭,就是野指針訪問(wèn)迁匠,會(huì)閃退。