Local variable assign versus direct assign; properties and memory.
Posted
by Typeoneerror
on Stack Overflow
See other posts from Stack Overflow
or by Typeoneerror
Published on 2010-06-18T02:17:41Z
Indexed on
2010/06/18
2:23 UTC
Read the original article
Hit count: 309
objective-c
|memory-management
In objective-c I see a lot of sample code where the author assigns a local variable, assigns it to a property, then releases the local variable. Is there a practical reason for doing this? I've been just assigning directly to the property for the most part. Would that cause a memory leak in any way? I guess I'd like to know if there's any difference between this:
HomeScreenBtns *localHomeScreenBtns = [[HomeScreenBtns alloc] init];
self.homeScreenBtns = localHomeScreenBtns;
[localHomeScreenBtns release];
and this:
self.homeScreenBtns = [[HomeScreenBtns alloc] init];
Assuming that homeScreenBtns is a property like so:
@property (nonatomic, retain) HomeScreenBtns *homeScreenBtns;
I'm getting ready to submit my application to the app store so I'm in full optimize/QA mode.
© Stack Overflow or respective owner