[英]alloc + init with synthesized property - does it cause retain count to increase by two?
[英]alloc init does not increase retain count
基本上,如果我願意(不是我想這樣做,只是我想了解)
array = [[NSMutableArray alloc] init];
array = [[NSMutableArray alloc] init];
array = [[NSMutableArray alloc] init];
數組現在應該具有3的保留計數嗎?
但是與我無關
您已分配了三個不同的NSMutableArray
,每個都有一個保留計數1。
其中的前兩個泄漏。
每次使用保留計數器創建新數組時。 要增加保留計數器,您必須執行以下操作:
array = [[NSMutableArray alloc] init];
[array retain];
[array retain];
nothing -/-> [array1 - count=1] (memory leak)
nothing -/-> [array2 - count=1] (memory leak)
array ---> [array3 - count=1]
不,不會。 實際上,這三個數組並不相同。 所有人都有不同的參考。
array = [[NSMutableArray alloc] init];
[array retain];
這將增加保留數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.