Program Crash Upon Switching Between Tabs 5 Times

2

I've got a strange bug I'm not sure how to track down. I'm running an app in the Simmulator 3.0. It has three tabs on the tabBarcontroller, let's call them tab1, tab2, and tab3. All three tabs are a sub-class of a customized grouped table. If I click back and forth between tab1 and tab3 indefinitely, there is no trouble. However, if I click from tab1 or tab3 to tab2 exactly five times, the program crashes after clicking back on tab1 or tab3. I've had two different backtraces (mostly identical) when I do this:

backtrace1:

objc[2988]: FREED(id): message release sent to freed object=0xfec100
Program received signal:  “EXC_BAD_INSTRUCTION”.
(gdb) backtrace
#0  0x92a2dbfa in _objc_error ()
#1  0x92a2dc30 in __objc_error ()
#2  0x92a2c637 in _freedHandler ()
#3  0x302042e8 in CFRelease ()
#4  0x00370c31 in CALayerUpdateSublayers ()
#5  0x0036f173 in -[CALayer dealloc] ()
#6  0x0036100e in CALayerRelease ()
#7  0x00369dad in CALayerFreeTransaction ()
#8  0x003620b8 in CA::Transaction::commit ()
#9  0x0036a2e0 in CA::Transaction::observer_callback ()
#10 0x30245c32 in __CFRunLoopDoObservers ()
#11 0x3024503f in CFRunLoopRunSpecific ()
#12 0x30244628 in CFRunLoopRunInMode ()
#13 0x32044c31 in GSEventRunModal ()
#14 0x32044cf6 in GSEventRun ()
#15 0x309021ee in UIApplicationMain ()
#16 0x0000208a in main (argc=1, argv=0xbfffefbc) at /Users/johnbulcher/Documents/myApps/AnApp/main.m:14

backtrace2:

Program received signal:  “EXC_BAD_ACCESS”.
(gdb) backtrace
#0  0x92a3d688 in objc_msgSend ()
#1  0x302042e8 in CFRelease ()
#2  0x00370c31 in CALayerUpdateSublayers ()
#3  0x0036f173 in -[CALayer dealloc] ()
#4  0x0036100e in CALayerRelease ()
#5  0x00369dad in CALayerFreeTransaction ()
#6  0x003620b8 in CA::Transaction::commit ()
#7  0x0036a2e0 in CA::Transaction::observer_callback ()
#8  0x30245c32 in __CFRunLoopDoObservers ()
#9  0x3024503f in CFRunLoopRunSpecific ()
#10 0x30244628 in CFRunLoopRunInMode ()
#11 0x32044c31 in GSEventRunModal ()
#12 0x32044cf6 in GSEventRun ()
#13 0x309021ee in UIApplicationMain ()
#14 0x0000208a in main (argc=1, argv=0xbfffefbc) at /Users/johnbulcher/Documents/myApps/AnApp/main.m:14

I have yet to be able to duplicate backtrace1, although backtrace2 is as consistent as clockwork. There are two strange things about this crash:

1) programmatically switching between tabs using "tabBarController.selectedIndex" does not crash the application - I have to manually select the tabs to crash the app. 2) I don't see any of my code indicated in the backtrace, aside from main. The line of code in main indicated in the backtrace is

 int retVal = UIApplicationMain(argc, argv, nil, @"AnAppDelegate");

Where should I start to look to solve this bug?

objective-c
iphone-sdk-3.0
asked on Stack Overflow Aug 21, 2009 by JoBu1324

2 Answers

1

Based on the stack traces it would appear the OS is finished with the transition from one view to the next and is trying to clean something up that's already been deallocated. My guess is there's something both your application and the OS are holding on to, but you've released your side more than you've retained it, causing a subsequent release by the OS to crash. The first backtrace is a double-free - releasing an object that's already been released; the second is trying to send a message to an object that no longer exists.

answered on Stack Overflow Aug 21, 2009 by fbrereto
0

(could not comment so I had to use the answer slot)

I am having a similar issue, also using custom table cells. My cells are created based on the tutorial found here (minutes 12:02 forward are the most relevant):

 MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
  [[NSBundle mainBundle] loadNibNamed:@"MyTableCellView" owner:self options:nil];
  cell = self.myTableCell;
 }

I have a MyTableCellView.xib which has its owner pointed to the TableViewController. The controller has a myTableCell IB outlet.

I have no issues/leaks whatsoever. Clang/LLVM shows no problems. I am doing a stress test with "Simulate memory warning" in the Simulator. The app crashes every time with an error similar to yours.

EDIT

Finally figured it out!

Well I did not know that you should nil out IBOutlets in didReceiveMemoryWarning (similar to viewDidUnload).

It would be good to have it reappear before the flipback so there is no "flickr" when going back to the main view after a memory notification.

answered on Stack Overflow Oct 7, 2009 by mga • edited Oct 7, 2009 by mga

User contributions licensed under CC BY-SA 3.0