开发者

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开发者_如何学JAVA 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?


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?


Is Instruments telling you this solely on the Simulator, or is it reporting the same thing on an actual device? If you don't get it on the device, then it's the Simulator - and that's known to happen (it isn't an exact match).

Also, down in dealloc, wouldn't it be [self.tableHeaderView release]? You have to be consistent with your usage.

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

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

Then the Property like this:

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

Then synthesize the getters/setters like this:

@synthesize MyObjectName=_MyObjectName;

Finally, refer to the object throughout the program with [self.MyObjectName ...];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜