Re: Autorelease Question
Re: Autorelease Question
- Subject: Re: Autorelease Question
- From: Luke the Hiesterman <email@hidden>
- Date: Wed, 19 Nov 2008 14:45:49 -0800
This is really an objective-c question (and there is an obj-c list).
Anyway, whenever you call a convenience class method +[NSString
stringWithString:] as opposed to doing an alloc/init you're getting
back an autoreleased object. So, if you're returning that value, it
would make sense to simply return. Whoever called your method will
have the responsibility of retaining. If you were interested in
retaining, it wouldn't make sense to use the convenience method in the
first place. Instead you would have done blah = [[NSString alloc]
initWithString];
Luke
On Nov 19, 2008, at 2:37 PM, Carmen Cerino Jr. wrote:
I am not sure the best way to phrase this question into words, so I
will phrase it using example code.
- (NSString*)foo
{
NSString blah = [NSString string];
.........
//Now do I do:
return blah;
//Or:
return [[blah retain] autorelease]];
}
_______________________________________________
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