When it comes to allocating and initializing objects that are declared @properties of a class I've seen two main patterns in various bits of sample code, so given the following (made up) header code —
@interface Class : Superclass {
Object *anObject;
}
@property (nonatomic, retain) Object *anObject;
The first, direct assignment:
self.anObject = [[Object alloc] init];
The second, indirect method creates a temporary object that is then assigned to the property and released:
Object *tempObject = [[Object alloc] init];
self.anObject = tempObject;
[tempObject release];
What's the benefit to the second method over the first?