should release or not? (basic memory management question)
should release or not? (basic memory management question)
- Subject: should release or not? (basic memory management question)
- From: Ignacio Enriquez <email@hidden>
- Date: Mon, 30 Mar 2009 04:24:32 +0900
Hi everyone.
I still have some doubts of should I release or not? and the most
important reaons why should I or why shouldn't I do it. Any answer
would be very appreciated.
Consider this:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *rawArray = [defaults objectForKey:@"lastArray"];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for(int i= 0; i< [rawArray count]; i++){
NSDictionary *dic = [rawArray objectAtIndex:i];
Mail *mail = [[Mail alloc] initWithDictionary:dic];
[tempArray addObject:mail];
[mail release];
}
theArray = tempArray;
Here theArray is a property:
@property (nonatomic, retain) NSArray *theArray;
So my doubts are:
Since is initialized by a class method , "defaults" must not be
released -> correct?
rawArray should be released? ([rawArray release] ?) I think the answer
is no but why?
dic should be released? ([dic release]?) I don't know...
tempArray should be released? I think the answer is: it depends.
Since theArray is retain I could do
self.theArray = tempArray;
[tempArray release];
or
theArray = tempArray;
so, what is the difference between using self and assigning tempArray
to theArray directly? (specifically in this case what is the
difference (in terms of retain count)?)
And what would happen with the retaincount of another object that was
theArray before tempArray assignation? (in case of doing theArray =
tempArray)
Thanks in advance.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden