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