views:

1164

answers:

2
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    AViewController * aView = [[AViewController alloc] initWithNibName:@"myNib" bundle:[NSBundle mainBundle]];    
    return vintagePriceRowView.view;
}

I know this code needs a release... somewhere. But where? If I set the allocated AviewController to autorelease, then touching elements within the view results in a "message sent to deallocated instance 0xfb5780"

The Leaks instrument is not actually showing a leak, but obviously Clang does not like the above code. I know Clang is not the gospel as far as determining everything that could possibly be wrong in your code, but in this case, it feels like it is probably right. I've allocated it, I need to release it.

Any ideas on what I am doing wrong?

+1  A: 

You need to hold on to it until it is not longer needed.

I suggest making a private property, set it to nil initially, and then lazy load the nib and assign the returned view to the property. Then in dealloc or in viewDidUnload simply set it to nil via the setter.

You will of course need to release or autorelease once you assigned it to the private property, since the setter will retain it for you.

freespace
+1  A: 

For efficiency's sake, you should create the view that you'll be using in the footer before it's required. Maybe create it in viewDidLoad in your tableViewController and store it in a member variable.

Then in your viewForFooter method simply return the view you stored earlier.

Then in your tableViewController's dealloc method, release the view.

Jasarien