Re: Methods that return autoreleased objects?
Re: Methods that return autoreleased objects?
- Subject: Re: Methods that return autoreleased objects?
- From: Mike Ferris <email@hidden>
- Date: Thu, 3 Jul 2008 08:21:11 -0700
And, as long as we're on the topic... who can name the only other
exceptional case for the "release only if you alloc,new, copy or
retain" rule? (It's pretty old-school...)
How about if you're implementing an initializer for a class cluster
that decides, perhaps based on parameters, that it wants to return
an instance of a subclass instead of self?
Ooh, good one. Not the one I was thinking of, but absolutely. In
this case you're basically fulfilling the contract of the +alloc that
came before. The caller of -init had a reference on thge object they
just +alloc'd, so if you're going to replace it (whether with a
subclass, a uniqued instance, or whatever) you need the replacement to
be similarly referenced (and you need to release the original "self".)
The one I was thinking of is more of an edge case, a straight-up
exception to the rule... it is:
-[NSCoder decodeValuesOfObjCTypes:, ...]
(But not it's singular variant, oddly enough.)
If you decode objects from a coder this way, they come out with a
reference. Not a common method and it has no counterpart in the new,
preferred, keyed NSCoder protocol.
Mike Ferris
_______________________________________________
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