title: How to track down strange crashes of iPad app in AQClient thread?
body: <p>My app recently started to show strange crashes I'm unable to track down to the source. Any help of what to look for would be helpful :) </p>
  
  <p>Crash logs from the device (an iOS 5 iPad) shows the following stuff at the beginning: </p>
  
  <pre><code>Date/Time:       2011-11-08 19:07:21.044 +0100
  OS Version:      iPhone OS 5.0 (9A334)
  Report Version:  104
  
  Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
  Exception Codes: KERN_INVALID_ADDRESS at 0x406cad3d
  Crashed Thread:  9
  </code></pre>
  
  <p>The crashed thread 9 is a <code>AQClient</code> thread and its stack trace looks like this: </p>
  
  <pre><code>Thread 9 name:  AQClient
  Thread 9 Crashed:
  0   libobjc.A.dylib                 0x30107fbc objc_msgSend + 16
  1   AVFoundation                    0x3420cdc8 _ZL27AudioPlayerAQOutputCallbackPvP16OpaqueAudioQueueP16AudioQueueBuffer + 28
  2   AudioToolbox                    0x32a409fe ClientMessageHandler::OutputBufferComplete(unsigned int) + 98
  3   AudioToolbox                    0x32a425d6 AQClientCallbackMessageReader::DispatchCallbacks(unsigned char*, unsigned int, void*, unsigned int) + 198
  4   AudioToolbox                    0x32a408dc AQCallbackReceiver_CallbackNotificationsAvailable + 364
  5   AudioToolbox                    0x329ee4b6 _XCallbackNotificationsAvailable + 54
  6   AudioToolbox                    0x329e436c mshMIGPerform + 368
  7   CoreFoundation                  0x34fa454c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
  8   CoreFoundation                  0x34fa44ee __CFRunLoopDoSource1 + 134
  9   CoreFoundation                  0x34fa333c __CFRunLoopRun + 1364
  10  CoreFoundation                  0x34f264d6 CFRunLoopRunSpecific + 294
  11  CoreFoundation                  0x34f2639e CFRunLoopRunInMode + 98
  12  AudioToolbox                    0x32a3d29c GenericRunLoopThread::Entry(void*) + 116
  13  AudioToolbox                    0x329c5aac CAPThread::Entry(CAPThread*) + 208
  14  libsystem_c.dylib               0x35756c16 _pthread_start + 314
  15  libsystem_c.dylib               0x35756ad0 thread_start + 0
  </code></pre>
  
  <p>This seems to be related to AVAudioPlayer or MPMoviePlayer activity. In the app I have a movie playing (.m4v from app's bundle), then when it's finished the view flips to the side without the movie and audio starts playing. </p>
  
  <p>In the case of crashes what I can hear is the same audio playing twice, even it's not intended. Then upon finishing the audio (when the AVAudioPlayer should be deallocated) the app crashes. </p>
  
  <p>I added some <code>NSLog</code>s to app to track down what's happening here. The console at the critical point showed me such a thing: </p>
  
  <pre><code>Nov  8 19:17:19 unknown XXX[1753] &lt;Warning&gt;: Finished movie
  Nov  8 19:17:19 unknown XXX[1753] &lt;Warning&gt;: Finished movie
  Nov  8 19:17:20 unknown XXX[1753] &lt;Warning&gt;: flipping
  Nov  8 19:17:20 unknown XXX[1753] &lt;Warning&gt;: flipping
  Nov  8 19:17:20 unknown XXX[1753] &lt;Warning&gt;: --&gt; dealloc &lt;AVAudioPlayer: 0x6887530&gt; (d2_s3_l3_q9.aif)
  Nov  8 19:17:20 unknown XXX[1753] &lt;Warning&gt;: --&gt; dealloc &lt;AVAudioPlayer: 0x6887530&gt; (d2_s3_l3_q9.aif)
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x68859f0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x11ef30 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x1a6720 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x6872400 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  
  (...) 
  
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x6872ed0 of class __NSCFDictionary autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x10cf80 of class __NSCFNumber autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x6850480 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x10a530 of class __NSCFNumber autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x1d15d0 of class __NSCFNumber autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x6884550 of class TFCrashHandler autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x685ec10 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:20 unknown UIKitApplication:com.bundle.name[0x2432][1753] &lt;Notice&gt;: objc[1753]: Object 0x6856270 of class __NSCFDictionary autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
  Nov  8 19:17:21 unknown com.apple.networkd[1763] &lt;Notice&gt;: main:212 networkd.1763 built Sep 16 2011 00:02:59
  Nov  8 19:17:25 unknown ReportCrash[1764] &lt;Notice&gt;: Formulating crash report for process XXX[1753]
  Nov  8 19:17:25 unknown com.apple.launchd[1] &lt;Warning&gt;: (UIKitApplication:com.bundle.name[0x2432]) Job appears to have crashed: Segmentation fault: 11
  Nov  8 19:17:25 unknown SpringBoard[15] &lt;Warning&gt;: Application 'XXX' exited abnormally with signal 11: Segmentation fault: 11
  Nov  8 19:17:25 unknown ReportCrash[1764] &lt;Error&gt;: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/XXX_2011-11-08-191724_iKotapad.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>The key part here, I think, is the doubled logs at the beginning. When non-crashing, it shows up once only. And, the problem could come from calling the <code>dealloc</code> method of the same object twice. </p>