Just from Curiosity… If I alter a pointer to point to an other autoreleased instance, the previous autoreleased instance that the pointer was pointing to, is autoreleased normally ? For example …
NSString pStr* = [NSString stringWithString:@"instance One"];
// do sth with pStr
pStr = [NSString stringWithString:@"Instance two"];
// do sth else with pStr
Are Both of the instances autoreleased ??
Yes. Lifecycle of objects doesn’t really depend on which variables point to them (unlike environments with garbage-collection). That’s why it’s possible to have variable pointing to deallocated object or have memory leaks: objects retained forever with no references to them.
Lifecycle depends on how objects are created and how you use
retain,releaseandautoreleasemethods.It’s explained in more details in Cocoa memory management guide.