• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
should release or not? (basic memory management question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: should release or not? (basic memory management question)
      • From: Clark Cox <email@hidden>
  • Prev by Date: Re: XMLParser
  • Next by Date: Re: NSArchiver atomic?
  • Previous by thread: Re: NSConfused... matrices and NSData
  • Next by thread: Re: should release or not? (basic memory management question)
  • Index(es):
    • Date
    • Thread