iPhone上的EXC_BAD_ACCESS,但模拟器上没有

时间:2011-01-27 19:54:31

标签: iphone objective-c sdk

当我在设备上运行应用程序(iPhone 4)时,我得到了这个exc_bad_access。我尝试通过将NSZombieEnabled设置为YES来启用僵尸。应用程序崩溃与exc_bad_access,但没有给我崩溃的原因。

我修复了构建和分析的所有错误,使用clang analyzer标记的scan-build。在模拟器上工作得很好。 App解析器xml使用libxml2并在UITableView上显示内容。任何帮助将不胜感激。

更新:添加(gdb)信息线程响应。有没有其他方法来调试我错过的EXC_BAD_ACCESS?

(gdb) bt
#0  0x33a0daba in CALayerStateRelease ()
#1  0x339f3d9e in CALayerFreeTransaction ()
#2  0x339f3330 in CA::Transaction::commit ()
#3  0x33a179bc in CA::Transaction::observer_callback ()
#4  0x3082823c in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#5  0x308280b0 in __CFRunLoopDoObservers ()
#6  0x3081f28c in CFRunLoopRunSpecific ()
#7  0x3081f17e in CFRunLoopRunInMode ()
#8  0x31e445f2 in GSEventRunModal ()
#9  0x31e4469e in GSEventRun ()
#10 0x31e51122 in -[UIApplication _run] ()
#11 0x31e4f12e in UIApplicationMain ()
#12 0x0000285e in main (argc=1, argv=0x2ffff53c) at /Users/Home/Desktop/ProductNavigation_libxml2_regular/main.m:14
(gdb) info threads
  6  (Thread 0x770b: user=0.000000 system=0.000000 cpu=0 sleep_time=0) 0x3027a19c in __workq_kernreturn ()
  5  (Thread 0x6e07: user=0.010000 system=0.010000 cpu=0 sleep_time=0) 0x30224060 in select$DARWIN_EXTSN ()
  4  (Thread 0x6103: user=0.030000 system=0.030000 cpu=0 sleep_time=0) 0x301ffc98 in mach_msg_trap ()
  3  (Thread 0x2003: user=0.000000 system=0.000000 cpu=0 sleep_time=0) 0x301ffc98 in mach_msg_trap ()
  2  (Thread 0x1703: user=0.000000 system=0.000000 cpu=0 sleep_time=0) 0x3022c330 in kevent ()
* 1  (Thread 0x0307: user=1.160000 system=1.160000 cpu=0 sleep_time=0) 0x33a0daba in CALayerStateRelease ()
(gdb) 

更新#2:另一个指向UITableView的堆栈跟踪

#0  0x3002d844 in objc_msgSend_stret ()
#1  0x31ed5b8e in -[UITableViewCellLayoutManager(UITableViewCellLayoutManagerStatic) _editingAccessoryRectForCell:offscreen:] ()
#2  0x31ed5374 in -[UITableViewCellLayoutManager(UITableViewCellLayoutManagerStatic) _reorderSeparatorRectForCell:offscreen:] ()
#3  0x31ed5266 in -[UITableViewCellLayoutManager reorderSeparatorEndingRectForCell:forNewEditingState:] ()
#4  0x31ed48ae in -[UITableViewCellLayoutManager layoutSubviewsOfCell:] ()
#5  0x3206ae24 in -[UITableViewCellLayoutManagerSubtitle layoutSubviewsOfCell:] ()
#6  0x31ed37c0 in -[UITableViewCell layoutSubviews] ()
#7  0x31e5cbc6 in -[UIView(CALayerDelegate) _layoutSublayersOfLayer:] ()
#8  0x308362ea in -[NSObject(NSObject) performSelector:withObject:] ()
#9  0x339f9948 in -[CALayer layoutSublayers] ()
#10 0x339f9700 in CALayerLayoutIfNeeded ()
#11 0x339f34ca in CA::Context::commit_transaction ()
#12 0x339f32e0 in CA::Transaction::commit ()
#13 0x33a179bc in CA::Transaction::observer_callback ()
#14 0x3082823c in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#15 0x308280b0 in __CFRunLoopDoObservers ()
#16 0x3081f6ba in __CFRunLoopRun ()
#17 0x3081f276 in CFRunLoopRunSpecific ()
#18 0x3081f17e in CFRunLoopRunInMode ()
#19 0x31e445f2 in GSEventRunModal ()
#20 0x31e4469e in GSEventRun ()
#21 0x31e51122 in -[UIApplication _run] ()
#22 0x31e4f12e in UIApplicationMain ()

4 个答案:

答案 0 :(得分:2)

让它在启用NSZombies的情况下运行,然后检查释放时应释放的内容(这听起来像是内存问题,尤其是因为堆栈跟踪)。

找到源代码后,修复它并感到高兴:)

答案 1 :(得分:1)

从代码中您评论print语句的位置跟随程序流程并验证您的对象是否已正确实例化并且还是正确发布的。

在我看来,当程序释放不存在的东西(已经或不存在)时程序会崩溃。最后一条消息是UITableViewCellLayout,它是从设置表格单元格的地方调用的(cellForRowAtIndexPath等)。

答案 2 :(得分:0)

从有限的信息来看,它看起来可能是一个打印问题。您是否正在登录文件?您要登录的目录(即允许您从应用程序写入文件的位置)在设备和模拟器上可能有所不同。我在记录一些调试信息时遇到过类似的问题。

答案 3 :(得分:0)

问题出在XML Parser上,解析完成之后释放解析器上下文用于崩溃。将其移至dealloc方法修复问题。感谢大家查看我的帖子,并在我的问题上花了一些时间。

相关问题