Literal NSStrings
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