Memory leak in loadNibNamed?

I am about to complete my first iPhone application and thought I launched it through the Performance Leaks tool. After fixing one obvious, the only one Iโ€™m left with is the one with Nib acting as a table header view loaded via loadNibNamed (here I followed the Demo Recipes).

- (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]; } 

The tools tell me that I miss 256 bytes with two leaks coming from the string using loadNibNamed. tableHeaderView is the only top-level object in Nib (I tested this in the debugger). Is there something that I forget to release? Am I misinterpreting what the Tools tells me? It is not right? Is this something the OS will clean up later?

+6
memory-leaks iphone cocoa nib
source share
2 answers

Are the tools telling about it exclusively on the simulator, or are you reporting this on the device itself? If you donโ€™t get it on the device, then this is a simulator - and this is known to happen (this is not an exact match).

Also, down in dealloc, would it be [self.tableHeaderView release] ? You must be compatible with your use.

To avoid confusion, in your .h you declare this:

 NS/UI/??xxxxxx *_MyObjectName; //notice the underscore 

Then a property like this:

 @property .... NS/UI/??xxxxxx *MyObjectName; //no underscore 

Then synthesize getters / setters as follows:

 @synthesize MyObjectName=_MyObjectName; 

Finally, access the object in the entire program using [self.MyObjectName ...];

+2
source share

When you load the tip, you are responsible for freeing all the top-level objects in the nib file. Is there anything in this file besides TableHeaderView?

+5
source share

All Articles