To be specific, I’m talking about writing a dealloc like so:
-(void)dealloc
{
self.myvar = nil;
[super dealloc];
}
I understand this goes against Apple’s recommendations. I also understand that it can cause issued with KVO as well using the setter on a partially deallocated object. But if I’m making the calls in this order (ie: setters first, then the [super dealloc]) is there any risk in doing this? I’m trying to understand exactly what the dangers are, and specifically why this is a Bad Thing(tm). Thanks….
in addition to the reasons stated (which can mean UB or disaster), you may end up with objects reconstructing themselves, and unnatural dependency cycles (e.g. among subclasses that override accessors) – the subclasses may have established their own dependencies, although the subclass’ ivars are (effectively) out of reach and should not be known to the superclass. it can severely restrict the usability of your objects for subclasses, and break their implementation (because their implementation may expect hacks, or may go through some form of resurrection). this is all stuff you want to avoid, and you should avoid accessors in init… for similar reasons. it gets ugly in large systems, and difficult to maintain – while the issue is easily avoided.