物件加入時retainCount自動+1,而物件移出後值-1
而與NSArray差異為此物件元素經宣告後無法變更,元素的內容,仍可變更
[self testArrary];
-(void)testArrary
{
NSMutableArray *array =[[NSMutableArray alloc] init];
NSObject *myObj4 = [[NSObject alloc] init];
[array addObject:myObj4];
NSLog(@"after add to array retainCount = %d",[myObj4 retainCount]);
[array removeObject:myObj4];
NSLog(@"after reomve from array retainCount = %d",[myObj4 retainCount]);
}
MyObject 已改用 NSObject
沒有留言:
張貼留言