I have an app that uses a tableview, along with a UIButton that I add as a subview to each custom cell, like this:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
checkButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(2.0, 2.0, 40.0, 40.0)];
[cell.contentView addSubview:checkButton];
// lot's of other code
return cell;
}
I thought all was fine until I started using Instruments to make sure I didn't have any memory leaks, but I've found that adding the UIButton as a subview of the cell like that somehow causes a leak within UIKit.
Specifically, I get a memory leak for each cell row (for each time the button is added as a subview), and the leaked object is "CALayer" with the responsible frame being "-[UIView _createLayerWithFrame:]".
Am I doing something wrong here?