• 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
Literal NSStrings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Literal NSStrings


  • Subject: Literal NSStrings
  • From: William Squires <email@hidden>
  • Date: Mon, 04 Jul 2011 19:23:54 -0500

Okay, sorry about this since I think I asked about it previously, but I forgot...

If a method (or even a C-style function) returns (NSString *), and I have a method/function like:

-(NSString *)bool2String:(BOOL)b
{
if (!b)
  {
  return @"NO";
  }
return @"YES";
}

is there ever a situation in which (properly written) client code could call this and trip over the memory  management rules? (as opposed to:

-(NSString *)bool2String(BOOL)b
{
if (!b)
  {
  return [NSString stringWithFormat:@"%@", @"NO");
  }
return [NSString stringWithFormat:@"%@", @"YES");
}

which, IIRC, would return an autoreleased NSString, correct?)
  This is, is a literal NSString autoreleased, or retained? Does it matter? I would guess that literal NSStrings are (effectively) retained, since they're not going anywhere (they're literal constants, after all), but they're not obtained by "New", "alloc", or "copy", which - according to the memory management rules, means you should retain them because they were autoreleased. Which is true?



_______________________________________________

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: Literal NSStrings
      • From: Jens Alfke <email@hidden>
    • Re: Literal NSStrings
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: Dumb question about multi-column NSTableViews
  • Next by Date: Re: Literal NSStrings
  • Previous by thread: Re: Dumb question about multi-column NSTableViews
  • Next by thread: Re: Literal NSStrings
  • Index(es):
    • Date
    • Thread