title: Program Crash Upon Switching Between Tabs 5 Times
body: <p>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:</p>
  
  <p><strong>backtrace1:</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>backtrace2:</strong>    </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I have yet to be able to duplicate backtrace1, although backtrace2 is as consistent as clockwork. There are two strange things about this crash:</p>
  
  <p>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</p>
  
  <pre><code> int retVal = UIApplicationMain(argc, argv, nil, @"AnAppDelegate");
  </code></pre>
  
  <p>Where should I start to look to solve this bug?</p>