Re: Autorelease accessors, was Re: NSEnumerator retaining objects?
Re: Autorelease accessors, was Re: NSEnumerator retaining objects?
- Subject: Re: Autorelease accessors, was Re: NSEnumerator retaining objects?
- From: Ricky Sharp <email@hidden>
- Date: Wed, 09 Mar 2005 12:30:39 -0600
On Wednesday, March 09, 2005, at 11:39AM, Mike R. Manzano <email@hidden> wrote:
>Is this an autorelease accessor?
>
>- (NSString*) getSomething
>{
> return [ NSString stringWithString:@"blah blah blah" ] ;
>}
>
>or
>
>- (NSString*) getSomethingElse
>{
> return [ [ [ aClass alloc ] init ] autorelease ] ;
>}
Both of these utlitmately return an autoreleased NSString instance.
>If so, I thought these were preferred ways of doing things?
It really depends. I typically use the 'return [[_object retain] autorelease]' pattern. But, there are cases where other patterns need to be used (e.g. returning a mutable copy of the object).
Definitely read up on the advantages/disadvantages of each pattern. I don't have the link handy, but there's a very good read on all this. I think mmalc put it together; the link I believe is one of those he has in his 'cocoa resources reminder' e-mails that is sent out every so often.
Finally, if you use Accessorizer, you can pick from many patterns to use for your accessors.
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden