views:

846

answers:

5

I'm doing this in dealloc of a view

[baseTable release];

In the header file, I declare it like this:

IBOutlet UITableView *baseTable;
....
@property(nonatomic, retain) UITableView *baseTable;

For some reason, I get a "EXC_BAD _ACCESS" in the dealloc. When I comment out the above line, all is well. How can I determine what specifically is going on with the UITableView and release?

+1  A: 

My guess is that you are releasing baseTable one too many times somewhere, have a look for a place where you are releasing it with out retaining.

You must have one and only one release for every retain, start from there and see how you go. The tricky bit is making sure that wherever you pass the baseTable object the release/retain match up. So it won't be as simple as a grep on [ baseTable release ] and count them unfortunately :)

hhafez
+1  A: 

Sounds like you're over-releasing baseTable. It's hard to say where that might be happening without seeing more of your code. Are you giving ownership of that table to the autorelease pool at any point? When you autorelease an object, you're transferring ownership to the autorelease pool and you need to be sure to abandon the object (and possibly nil out its instance variable).

You need to examine every use of baseTable and make sure that any object that might assume ownership of the table retains it before releasing it. Also remember that you may be referencing the table object through an alias as a parameter to a UITableViewDelegate or UITableViewDataSource method.

Don McCaughey
+2  A: 

If you want to find out the exact reason for the EXC_BAD_ACCESS bug, enable NSZombie, so that any time you call any method on a deallocated object, it tells you exactly what object and what method it is.

To enable NSZombie:

  1. Expand the Executables section in the "Groups and Files" window on the left.
  2. Open the properties of the executable.
  3. Find the "Arguments" section (It's on the bottom half of the screen, I forget what tab it's in)
  4. Add a new argument "NSZombieEnabled" with value "YES"

To disable it, either delete the value or uncheck it if you may want to turn it on again later. Be sure to not leave it on, because it doesn't actually deallocate anything when enabled!

Ed Marty
A: 

I have this problem too

I release the ABRecordRef which was obtained through the ABAddressBookCopyArrayofAllPeople() after dealloc and pop back to the rootViewController my app is dead too