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
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 mails | Author | Date |
|---|---|---|
| john muchow | Jun 29, 02:25 | |
| Shawn Erickson | Jun 29, 02:34 | |
| Markus Spoettl | Jun 29, 02:43 | |
| Owen Yamauchi | Jun 29, 03:29 | |
| Charles Srstka | Jun 29, 06:59 | |
| mmalc crawford | Jun 29, 08:58 | |
| Charles Srstka | Jun 29, 17:02 | |
| mmalc crawford | Jun 29, 17:13 | |
| Mike Ferris | Jun 29, 18:42 | |
| Adam R. Maxwell | Jun 29, 18:55 | |
| Tom Bunch | Jul 1, 00:12 | |
| Mike Ferris | Jul 3, 17:21 |






Cocoa mail archive

