Properly releasing UITableViewController and UITableView directly added to a UIViewController

Posted by JK on Stack Overflow See other posts from Stack Overflow or by JK
Published on 2010-05-21T06:14:16Z Indexed on 2010/05/21 6:20 UTC
Read the original article Hit count: 249

Filed under:
|

I have a UIViewController (parentVC) to which I add a UITableViewController as follows (it is not pushed since the tableview only occupies about half the screen):

tableVC = [[SmallTableVC alloc] initWithStyle:UITableViewStylePlain];
          [self.view addSubview:tableVC.tableView];

In dealloc, I add [tableVC release];

Using instruments, I can see that the tableVC is indeed fully released when parentVC released, which is good, but I am not sure why as I thought that the UITableView of tableVC would have a retain count of 2 (1 for retention by tableVC and 1 for retention by parentVC). My intuition was that an additional [tableVC.tableView release] would be required, but adding it crashes the app. Why is tableVC released properly by the current code (if indeed it actually is)? Does a UITableViewController not retain its tableView? Thanks.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch