views:

185

answers:

1

I have got custom TableViewCell-s where I assign several UIImageView-s and UILabel-s to the cell's contentview, like this:

[cell.contentView addSubview:iconFileView];
[iconFileView release];
[cell.contentView addSubview:areaLabel];
[areaLabel release];
[cell.contentView addSubview:placeLabel];
[placeLabel release];

As I understand the cells themselves are retained by the TableView and will be released together with it. However, I do not understand do I have to remove the cell's contentview's subviews from the contentview in order for them to be released?

If the answer is yes: how do I actually do that? Is it sufficient to find all the visible cells and remove their subviews from each cell?

Neither could find an exact answer to this question in Memory Management Guide for Cocoa.

Thanks!

+1  A: 

The contentView will take care of releasing its subviews when the cell releases the contentView. Basically, when cell's retain count goes to zero, it will send a release message to contentView. If contentView's retain count is zero, then it will send release messages to all its subviews, including iconFileView, etc. As long as you haven't sent any additional retain messages to contentView or iconFileView, etc., you should be fine.

If you want to feel really good, run your program under Leaks in Instruments. Make sure you do whatever needs to be done to cause the UITableViewCells to be released.

Rob Jones