Search code examples
iphoneuitableviewdeallocsuper

super dealloc error using multiple table view classes


I am new to Iphone apps and I am trying to build a tab based app. I am attempting to have a table ontop of an image in both tabs. On tab with a table of audio links and the other tab with a table of video links.

This has all gone swimmingly, I have created two viewControllers for the two tables. All the code works great apart from to get it to work I have to comment out the super dealloc in the - (void)dealloc {} in the videoTableViewController for the second tab.

If I don't I get the error message:

FREED(id): message numberOfSectionsInTableView: sent to freed object

please help, i have no idea why it is doing this...


Solution

  • UITableViewController handles memory management for its own tableView object, so you theoretically don't have to worry about it.

    As Alex said, it's definitely bad to not call [super dealloc]; it is a memory leak to leave that out.

    To solve this, you need to figure out why your table view is living longer than your view controller (that's what's giving you that FREED(id) error). One guess is that you're leaving the view in the view hierarchy but releasing the controller. The desired behavior when you're moving away from one view controller to another is to remove the old view from the view hierarchy by calling [oldView removeFromSuperview] and then releasing the view controller, if you want to release it at all. The reason removeFromSuperview is important is that superviews always retain their subviews, so this could be why your tableView is so undead.

    If your app is not memory intensive, it may be easiest to simply keep your view controllers allocated (not release them) -- that would solve your problem, although it is not really addressing the issue that your table view is living longer than expected, which may be a symptom of some inefficient code that would be nice to clean up.