All this time I never paid much attention to memory management, but it is time to take a deeper look at it.
In Cocoa Dev Central, I found this setter method:
- (void) setPhotographer: (NSString*)input
{
[photographer autorelease];
photographer = [input retain];
}
I think I understand why we write [input retain], but why [photographer autorelease];?
I see, autorelease will, well, release the object "soon", and I can be sure that the object will remain intact until the end of the function. But, why release photographer? I am going to set it a different value in this function (input), no? I mean, I release things that I won't be using anymore, right? Why would I release/autorelease photographer if I am still going to use it?
This might be quite a newbie question, I fear this stuff of memory management was never my favorite concept in Objective-C..