Skip navigation.
 
mlRe: Methods that return autoreleased objects?
FROM : Mike Ferris
DATE : Thu Jul 03 17:21:11 2008

>>
>> 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

Related mailsAuthorDate
mlMethods that return autoreleased objects? john muchow Jun 29, 02:25
mlRe: Methods that return autoreleased objects? Shawn Erickson Jun 29, 02:34
mlRe: Methods that return autoreleased objects? Markus Spoettl Jun 29, 02:43
mlRe: Methods that return autoreleased objects? Owen Yamauchi Jun 29, 03:29
mlRe: Methods that return autoreleased objects? Charles Srstka Jun 29, 06:59
mlRe: Methods that return autoreleased objects? mmalc crawford Jun 29, 08:58
mlRe: Methods that return autoreleased objects? Charles Srstka Jun 29, 17:02
mlRe: Methods that return autoreleased objects? mmalc crawford Jun 29, 17:13
mlRe: Methods that return autoreleased objects? Mike Ferris Jun 29, 18:42
mlRe: Methods that return autoreleased objects? Adam R. Maxwell Jun 29, 18:55
mlRe: Methods that return autoreleased objects? Tom Bunch Jul 1, 00:12
mlRe: Methods that return autoreleased objects? Mike Ferris Jul 3, 17:21