I am new to objective c and am trying to understand how/when autorelease is called. I understand the simple use case of:
- (void) foo {
Bar *b = [[[Bar alloc] init] autorelease];
[self doSomething:b];
}
What about this next case -- is this a bug, because the object will be immediately released upon leaving the scope of makeBar?
-(Bar*) makeBar
{
return [[[Bar alloc] init] autorelease];
}
What if the caller does a retain?
Bar *b = [[self makeBar] retain];
Thanks, -Eric