Question

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...

Was it helpful?

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.

OTHER TIPS

If you're not calling [super dealloc], then your object isn't being deallocated and you're leaking memory. You need to uncomment that call to [super dealloc].

The exception you note above means that a table view is still trying to access your deallocated object as a data source. This is the problem you need to solve. Presumably, the table view that's making this call is owned by the view controller that's been deallocated.

If your view controller is not a subclass of UITableViewController, then you will need to release the table view reference you're holding. If it is a subclass of UITableViewController, then there must be some other place where that table view is being retained where it shouldn't be.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top