Just when I thought I've understood this topic completely, I'm back to basics.
I have a method that instantiates an autoreleased object, using (for example) stringWithFormat
:
return [NSString stringWithFormat:@"what"];
Then I call this method from another method, and another method, each time returning this autoreleased NSString
and in each level of the hierarchy. The code works fine and the NSString
instance is intact at each level of the hierarchy.
I thought that since the instance is autoreleased, it could suddenly end up with a retainCount
of 0 at any point in the call stack (i.e., one of the methods would be working on a released object). Is it true that I cannot depend on this object?
Edit: I realize the question wasn't too clear. Sorry. I mean:
Method1 ---calls---> Method2 ---calls---> Method3 ---instantiates the string--->
return @"what";
, which is the same in this example, I think. – Magnitogorsk