Subject: should release or not? (basic memory management
question)



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 (Cocoa-dev@xxxxxxxxxxxxxxx)

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:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx



Privacy