Deleting object from array
i'm working on app for iphone on objective-c i have array with object references If i remove item wi开发者_运维知识库th object reference from array should i release this object additionally or it will be removed from memory automatically?
When removed from array object gets released once. So if your retain/release are paired correctly in other places you must not release your object in this case.
If the NSArray
(um, it is an NSArray
, isn't it? C arrays provide no ownership management) is the only thing that owns the object -- that is, if the object added was acquired autorelease
-d or you explicitly called release
after adding -- then it will be cleaned up automatically on removal. Any other ownership claims will still need to be release
-d as normal.
In fact, your talking about NSMutableArray
And it does the release 'automatically'. So do
[array add: @"SAFEY-STRING" ];
and don't do
[array add: [[NSString alloc] initWithFormat:@"LEAKY-STRING"] ];
精彩评论