我是新來的目標C,我有一個帶有3個對象的NSMutableArray,然後嘗試打印數組的retainCount。爲什麼最後的retainCount返回-1?由於在目標C中保留計數C返回-1
NSLog(@"myArray has retain count of %d", [myArray retainCount]);
[myArray release];
NSLog(@"myArray has retain count of %d", [myArray retainCount]);
結果從控制檯:
2010-10-17 11:58:06.407 TestRetainCount [527:a0f] myArray has retain count of 1
2010-10-17 11:58:06.407 TestRetainCount [527:a0f] myArray has retain count of -1
GC中沒有保留計數(至少不是ObjC條款)。而且,正如格雷厄姆所說的那樣,您實際上從來沒有看到保留計數爲0,因爲該對象在那段時間已經被釋放。 – bbum 2010-10-31 18:30:57