• 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
Re: Retain
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Retain


  • Subject: Re: Retain
  • From: Mike Abdullah <email@hidden>
  • Date: Fri, 24 Oct 2008 16:23:52 +0100

This sort of question comes up every couple of weeks. You did not use +alloc to create the string, so you do NOT need to release it. If you try to release it, the app will crash. Any of these are correct:

NSString w = [NSString stringWithFormat:@"something %i", x];
// Do stuff


NSString w = [[NSString alloc] initWithFormat:@"something %i", x]; // Do stuff [w release];


NSString w = [NSString stringWithFormat:@"something %i", x]; [w retain]; // Do stuff [w release];


BUT NOT:

NSString w = [NSString stringWithFormat:@"something %i", x];
// Do stuff
[w release];	// Will crash here


On 24 Oct 2008, at 06:24, Ron Green wrote:

If I call NSString w = [NSString stringWithFormat:@"something %i", x];

Am I now suppose to call retain on w?
When I'm done I know I'm suppose to release w.
_______________________________________________

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

_______________________________________________

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: Retain
      • From: Dave Carrigan <email@hidden>
    • Re: Retain
      • From: Devon Ferns <email@hidden>
References: 
 >Retain (From: Ron Green <email@hidden>)

  • Prev by Date: Re: File event notification
  • Next by Date: Re: Retain
  • Previous by thread: Re: Retain
  • Next by thread: Re: Retain
  • Index(es):
    • Date
    • Thread