Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory leak in loadNibNamed?

I'm about to wrap up my first iPhone app and figured I'd run it through the Leaks Performance Tool. After fixing one obvious one, the only one I have left is one with a Nib acting as a table header view loaded through loadNibNamed (I was following the Recipes demo here).


- (void)viewDidLoad {
    [super viewDidLoad];

    if (self.tableHeaderView == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"TableHeaderView" owner:self options:nil];
        self.tableView.tableHeaderView = self.tableHeaderView;
    }
}

Then in dealloc:


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

Instruments tells me that I'm leaking 256 bytes with 2 leaks coming from the line with loadNibNamed. tableHeaderView is the only top level object in the Nib (I've verified that in the debugger). Is there something I'm forgetting to release? Am I misinterpreting what Instruments is telling me? Is it wrong? Is it something that the OS will clean up later?

like image 843
AndrewO Avatar asked Oct 29 '09 19:10

AndrewO


1 Answers

When you load a nib, you're responsible for releasing all of the top-level objects in the nib file. Is there anything in that file besides the TableHeaderView?

like image 123
NSResponder Avatar answered Oct 21 '22 02:10

NSResponder