iOS / iPhone ARC内存管理

时间:2013-06-12 12:16:02

标签: iphone ios memory-management null automatic-ref-counting

 __weak NSString *strin = [[NSString alloc] initWithFormat:@"hey"] ;

    NSLog(@"weak %@",strin); //returns weak (null)

__weak NSString *strin =@"hey";

NSLog(@"weak %@",strin); //returns weak hey

两个片段之间有什么区别。为什么第二个在分配弱时返回值?

2 个答案:

答案 0 :(得分:4)

这是因为@"hey"是一个常量字符串文字,它将永远存在,而对第一个(已分配)字符串的弱引用不足以使其保持活动状态。

答案 1 :(得分:1)

检查下面的按钮,你会得到自己的答案。

enter image description here

相关问题