Say I read an object from an NSArray and retain that object. I am then done with the NSArray and release it. That NSArray now has a retain count of zero. Is it deallocated or will it be forced to stick around until the child object is deallocated as well?
Bas开发者_Go百科ically what I am asking if I need to copy the child instead of retaining it when the child will be kept for a while but the array isn't needed?
I am thinking that a retain is fine and the NSArray will be deallocated, but I want to make sure.
Because you've retained the object within the NSArray it (in comparison with the other objects in the array) will have a retain count of two. (One from the NSArray, and one from you.)
As such, when the NSArray is released your object will still have a retain count of one and will therefore still be around after the autorelease pool is emptied. (Until of course you release it.)
精彩评论