简体   繁体   中英

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.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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