如何排查EXC_BAD_ACCESS错误

如何排查EXC_BAD_ACCESS错误,第1张

概述刚开始学obj-c,遇到这个问题,网上搜了下,说的都有点短(本人愚钝,理解能力弱~~)。搞定后发上来,记录、共享。。 我的xcode是4.2的 *** 作如下: 1、增加NSZombieEnabled和MallocStackLogging环境变量:菜单Product--》Edit Scheme...,在d出的窗口上方选择自己的项目及模拟器,左侧选择"Run ***.app"(***是你的项目名称),右侧

刚开始学obj-c,遇到这个问题,网上搜了下,说的都有点短(本人愚钝,理解能力弱~~)。搞定后发上来,记录、共享。。

我的xcode是4.2的

*** 作如下:

1、增加NSZombIEEnabled和MallocStackLogging环境变量:菜单Product--》Edit Scheme...,在d出的窗口上方选择自己的项目及模拟器,左侧选择"Run ***.app"(***是你的项目名称),右侧选择Arguments选项卡,在Environment Variables中增加name:NSZombIEEnabled--》Value:YES、name:MallocStackLogging--》Value:YES,并点击2个环境变量左侧的复选框,保证在启用状态。

2、deBUG自己的项目,出现EXC_BAD_ACCESS错误的时候,在控制台会出现类似下面的log

写道 fbft(1431) malloc: recording malloc stacks to disk using standard recorder
fbft(1431) malloc: process 1249 no longer exists,stack logs deleted from /tmp/stack-logs.1249.fbft.bBsBO7.index
fbft(1431) malloc: stack logs being written into /tmp/stack-logs.1431.fbft.Fz32vw.index
2012-01-18 11:38:55.118 fbft[ 1431:ef03] *** -[_ UIResizableImage release]: message sent to deallocated instance 0x7245470

从最后一行可以看出是调用了已经被dealloc的对象。(UIResizableImage应该是已经release的对象类型)

3、在控制台的(gdb)后面输入shell malloc_history 1431 0x7245470(其中1431和0x7245470是上面log中的pID和address),并回车。得到如下信息

写道 ......

ALLOC 0x7245470-0x72454af [size=64]: thread_b024f000 |thread_start | _pthread_start | _ZN2KBL14BackgroundLoadEPv | KB::DynamicDictionaryImpl::background_load_address_book(KB::StaticDictionary const&) | KB::fill_with_matchable_strings_from_address_book(KB::Hashmap<KB::String,bool>&) | ABAddressBookCreate | ABCCreateAddressBookWithDatabaseDirectory | ABCCreateAddressBookWithDatabaseDirectoryAndForceInProcessMigrationInProcesslinkingAndresetSortKeys | ABCDBContextCreateWithPathAndAddressBook | CPsqliteDatabaseRegisterFunction | CPsqliteDatabaseConnectionForWriting | _connectAndCheckVersion | _createConnectionForWriting | CPsqliteConnectionPerformsql | CPsqliteConnectionStatementForsqlAndIgnoreErrors | CPsqlitePreparedStatement | sqlite3_prepare_v2 | sqlite3LockAndPrepare | sqlite3Prepare | sqlite3RunParser | sqlite3Parser | yy_reduce | sqlite3Pragma | sqlite3Init | sqlite3InitOne | sqlite3_exec | sqlite3InitCallback | sqlite3LockAndPrepare | sqlite3Prepare | sqlite3RunParser | sqlite3Parser | yy_reduce | sqlite3ExprAlloc | sqlite3DbMallocRaw | sqlite3Memmalloc | malloc_zone_malloc
----
FREE 0x7245470-0x72454af [size=64]: thread_b024f000 |thread_start | _pthread_start | _ZN2KBL14BackgroundLoadEPv | KB::DynamicDictionaryImpl::background_load_address_book(KB::StaticDictionary const&) | KB::fill_with_matchable_strings_from_address_book(KB::Hashmap<KB::String,bool>&) | ABAddressBookCreate | ABCCreateAddressBookWithDatabaseDirectory | ABCCreateAddressBookWithDatabaseDirectoryAndForceInProcessMigrationInProcesslinkingAndresetSortKeys | ABCDBContextCreateWithPathAndAddressBook | CPsqliteDatabaseRegisterFunction | CPsqliteDatabaseConnectionForWriting | _connectAndCheckVersion | _createConnectionForWriting | CPsqliteConnectionPerformsql | CPsqliteConnectionStatementForsqlAndIgnoreErrors | CPsqlitePreparedStatement | sqlite3_prepare_v2 | sqlite3LockAndPrepare | sqlite3Prepare | sqlite3RunParser | sqlite3Parser | yy_reduce | sqlite3Pragma | sqlite3Init | sqlite3InitOne | sqlite3_exec | sqlite3InitCallback | sqlite3LockAndPrepare | sqlite3Prepare | sqlite3RunParser | sqlite3Parser | yy_reduce | sqlite3ExprDelete | sqlite3ExprDelete | sqlite3ExprDelete | sqlite3ExprDelete | sqlite3ExprDelete | sqlite3ExprListDelete | sqlite3ExprDelete | sqlite3DbFree | sqlite3MemFree | malloc_zone_free

ALLOC 0x7245470-0x7245493 [size=36]: thread_ad12a2c0 |start | main | UIApplicationMain | -[UIApplication _run] | CFRunLoopRunInMode | CFRunLoopRunspecific | __CFRunLoopRun | __CFRunLoopDoSource1 | __CFRUNLOOP_IS_CALliNG_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ | PurpleEventCallback | _UIApplicationHandleEvent | -[UIApplication sendEvent:] | -[UIApplication handleEvent:withNewEvent:] | -[UIApplication _runWithURL:payload:launchOrIEntation:statusbarStyle:statusbarHIDden:] | -[UIApplication _callinitializationDelegatesForURL:payload:suspended:] | -[FbftAppDelegate application:dIDFinishLaunchingWithOptions:] | -[UIWindow makeKeyAndVisible] | -[UIWindow _orderFrontWithoutMakingKey] | -[UIWindow _setHIDden:forced:] | -[UIWindow addRootVIEwControllerVIEwIfPossible] | -[UIVIEwController vIEw] | -[ TestVIEwController vIEwDIDLoad] | -[UIImage(UIImageDeprecated) stretchableImageWithleftCapWIDth:topCapHeight :] | -[UIImage(UIImagePrivate) _stretchableImageWithCAPInsets:] | -[UIImage resizableImageWithCAPInsets:] | _objc_rootAlloc | +[NSObject allocWithZone:] | _objc_rootAllocWithZone | class_createInstance | calloc | malloc_zone_calloc

Binary Images:
0x1000 - 0x3ffb +fbft (??? - ???) <92BCD2F3-83ED-36DD-A56A-37022E0229E0> /Users/fangjiawang/library/Application Support/iPhone Simulator/5.0/Applications/8ED06429-A51E-4D6C-9ACC-C9A6E269C80A/fbft.app/fbft
0x7000 - 0x612fff +UIKit (1600.0.0 - comp
.......

从上面标红的log中可以大概知道是哪里的代码出了问题,TestVIEwController类中的stretchableImageWithleftCapWIDth:topCapHeight方法中引入了已经release对象

PS-疑问:配置的两个环境变量,对发布出来的应用有影响吗?有答案的留下言~ 谢谢~~

总结

以上是内存溢出为你收集整理的如何排查EXC_BAD_ACCESS错误全部内容,希望文章能够帮你解决如何排查EXC_BAD_ACCESS错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1182177.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存