Search code examples
iosobjective-cmemory-managementretain

Release retain property in dealloc?


I have a class with a property defined in the .h file as:

@property (retain) NSString *fontName;

In the .m file I release the property:

-(void)dealloc {
    [super dealloc];
    [_fontName release];
}

Now I'm occasionally getting a EXC_BAD_ACCESS error on [_fontName release]. The occurrence is so rare that I'm not really sure how to debug it. Is is correct to release a @property (retain)? Or does [super dealloc] already do that?


Solution

  • Perform the super dealloc AFTER:

    -(void)dealloc {
        [_fontName release];
        [super dealloc];
    }
    

    In short, kill your children before killing yourself.