UITableViewDelegate memory leak

Hi,

I was wondering if anyone else has notices some strange memory leaks happening in UITableViewDelegates heightForRowAtIndexPath: method. I created this simple test case to reproduce the problem:


@implementation MyView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame])
{
UITableView *table = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
table.dataSource = self;
table.delegate = self;

[self addSubview:table];
[table release];

}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return 100;
}
// Comment this and no memory leaks should happen
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

return 100.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
if (cell == nil) {
// Create a new cell. CGRectZero allows the cell to determine the appropriate size.
CGRect frame;
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"reuse"] autorelease];
cell.text = @"Testing";
}

return cell;
}
@end


If this view is created and added to the application window the Instument says that IndexPath is leaking memory. On the other hand if heightForRowAtIndexPath:is removed (commented out) no memory leaks happen.

So my question is has someone else also noticed this or can someone verify this. Or am I missing something very simple here. Appriciate all the help.

-Mika

MacBook, Mac OS X (10.5.5)

Posted on Nov 20, 2008 10:38 AM

Reply
3 replies

Nov 20, 2008 11:11 AM in response to Detrie

I vaguely remember this happening to me. Is MyView inheriting from UITableViewController?

I believe I changed the super of myView from UITableViewController to UIViewController and the NSIndexPath leak went away.

If you do that then you have to do a few extra things in your implementation (I believe it was deselecting the row or something) but I didn't notice any difference myself.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

UITableViewDelegate memory leak

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.