-(Bar*) makeBar { return [[[Bar alloc] init] autorelease]; }
The second case is the preferred way to return an Objective-C object. With the exception of +alloc , +alloc -copy... and -create... , the method should not preserve ownership of the returned object, i.e. The save (change) account must be 0.
However, [[Bar alloc] init] forces the object to have keepCount +1 so that it must release it before returning. But -release immediately free the object, making the method useless. -autorelease is used for this - it is delayed -release , that is, the object will be released in the end, but not now, so other parts of the code can still interact with it, but the save account can still be balanced to 0.
Bar *b = [[self makeBar] retain];
You should not save it if you do not want to be a long-term owner of the property b .
kennytm
source share