简体   繁体   English

iOS / iPhone ARC内存管理

[英]iOS/iPhone ARC memory management

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

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

__weak NSString *strin =@"hey";

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

What is the difference between both the snippets. 两个片段之间有什么区别。 Why the second is returning the value when weak is assigned ? 为什么第二个在分配弱时返回值?

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

Check below snap and you will get your answer your self. 检查下面的快照,你会得到自己的答案。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM