If I have a function like this
void setSomeObject( SomeObjectClass obj /*, and some other params*/ )
{
[_previous autorelease];
_previous = obj;
}
As far as I understood it the autorelease message is sent to the object itself (not _previous)
so at one point, sometime when setSomeObject goes out of scope the original object is autoreleased (if any). Is this correct? I am not using properties but I guess by using them the release of the previous object would be automatic when I do self.previous = obj; ?
When you send an
-autoreleasemessage to an object, it’s added to the activeNSAutoreleasePool, which is emptied when the run loop runs. If you say[_previous autorelease], only that object will be autoreleased, and if you then say_previous = obj, that only changes the variable’s reference. The old object is still autoreleased.If you’re doing this in a setter method, this is what the pattern generally is: