I might've jumped into Objective-C a little too fast and assumed I knew enough about memory management to dive in. Turns out I wasn't.
Fast forward a bit and I've caught up ... for the most part. One of my last remaining questions regards the @property/@synthesize process and setting those values properly.
I've often seen this:
SomeObject *obj = [[SomeObject alloc] init];
self.obj = obj;
[obj release];
It makes sense, but I wonder if this accomplishes a similar enough thing to be an alternative:
self.obj = [[[SomeObject alloc] init] autorelease];
Would that be acceptable anywhere you might set the value of the @property
, obj
? Or is direct access to the instance variable preferred over both of those in the init
method?
obj = [[SomeObject alloc] init];
Thanks.
EDIT: Definitely related question that discusses half of my question. The autorelease
part of my question is referenced in one of the answers, but has not been confirmed.
So my questions still remain:
- Is
autorelease
a valid alternative in this situation? - Can
autorelease
be used this way in theinit
method, or should the instance variable always be set directly in theinit
method?