Re: NSDictionary, allKeys and the NSAutoreleasePool
Re: NSDictionary, allKeys and the NSAutoreleasePool
- Subject: Re: NSDictionary, allKeys and the NSAutoreleasePool
- From: Jens Alfke <email@hidden>
- Date: Thu, 3 Sep 2009 11:47:42 -0700
On Sep 3, 2009, at 11:40 AM, Scott Andrew wrote:
I could have sworn in either the apple docs (or one of the cocoa
books, maybe this board). I maybe thinking of the general rule that
you don't own the object until you retain it and its only valid or
the within the method that its recieved. My bad.
Here's an example of a return value that isn't autoreleased:
- (Foo*) foo {
static Foo* sharedFoo;
if (!sharedFoo) sharedFoo = [[Foo alloc] init];
return _sharedFoo;
}
Another example is a simple getter that simply returns an instance
variable (which is the way I still choose to write most of my getters.)
The general principle is that returned object references are not
guaranteed to stick around, unless you retain them. Autoreleasing is
just one way for the called method to do that.
—Jens_______________________________________________
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