Skip navigation.
 
mlRe: Best practice for overridden initializers in subclasses
FROM : Chris Suter
DATE : Wed Mar 26 01:42:25 2008

On 26/03/2008, at 11:09 AM, Quincey Morris wrote:

> Unless there is some special runtime magic going on, this seems not 
> absolutely safe. Your '[self release]' is going to eventually lead 
> to a call of '[super dealloc]' and theoretically you can't safely 
> call the superclass's dealloc if you haven't called a designated 
> superclass initializer, because you don't know what the superclass's 
> dealloc expects its initializer to have already done.
>
> In practice, though, I can't imagine anything really bad happening 
> -- all the dealloc has available to run amok with is a bunch of 
> zeroes.


Well, I have actually had that problem happen to me. I was sub-
classing NSDate and releasing without calling the NSDate initialiser 
and that was causing a crash. Apple updated the documentation shortly 
after I reported it to them. It looks like they've fixed the cause of 
the crash in Leopard. I personally think that you should be able to 
call dealloc before calling any initialiser. Maybe the documentation 
can be updated to remove that requirement now that NSDate has been 
fixed (I've just logged a report asking for this).

- Chris

Related mailsAuthorDate
mlBest practice for overridden initializers in subclasses Andy Klepack Mar 25, 23:01
mlRe: Best practice for overridden initializers in subclasses Quincey Morris Mar 26, 00:06
mlRe: Best practice for overridden initializers in subclasses Andy Lee Mar 26, 00:26
mlRe: Best practice for overridden initializers in subclasses Kyle Sluder Mar 26, 00:38
mlRe: Best practice for overridden initializers in subclasses Quincey Morris Mar 26, 01:09
mlRe: Best practice for overridden initializers in subclasses Chris Suter Mar 26, 01:42
mlRe: Best practice for overridden initializers in subclasses Andy Lee Mar 26, 04:47