簡體   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

兩個片段之間有什么區別。 為什么第二個在分配弱時返回值?

這是因為@"hey"是一個常量字符串文字,它將永遠存在,而對第一個(已分配)字符串的弱引用不足以使其保持活動狀態。

檢查下面的快照,你會得到自己的答案。

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM