Is it OK to write code after [super dealloc]? (Objective-C)
- by Richard J. Ross III
I have a situation in my code, where I cannot clean up my classes objects without first calling [super dealloc]. It is something like this:
// Baseclass.m
@implmentation Baseclass
...
-(void) dealloc
{
[self _removeAllData];
[aVariableThatBelongsToMe release];
[anotherVariableThatBelongsToMe release];
[super dealloc];
}
...
@end
This works great. My problem is, when I went to subclass this huge and nasty class (over 2000 lines of gross code), I ran into a problem: when I released my objects before calling [super dealloc] I had zombies running through the code that were activated when I called the [self _removeAllData] method.
// Subclass.m
@implementation Subclass
...
-(void) deallloc
{
[super dealloc];
[someObjectUsedInTheRemoveAllDataMethod release];
}
...
@end
This works great, and It didn't require me to refactor any code. My question Is this: Is it safe for me to do this, or should I refactor my code? Or maybe autorelease the objects?
I am programming for iPhone if that matters any.