如何排查EXC_BAD_ACCESS错误
来源:互联网 发布:屏幕截取软件 编辑:程序博客网 时间:2024/04/30 07:06
刚开始学obj-c,遇到这个问题,网上搜了下,说的都有点短(本人愚钝,理解能力弱~~)。搞定后发上来,记录、共享。。
我的xcode是4.2的
操作如下:
1、增加NSZombieEnabled和MallocStackLogging环境变量:菜单Product--》Edit Scheme...,在弹出的窗口上方选择自己的项目及模拟器,左侧选择"Run ***.app"(***是你的项目名称),右侧选择Arguments选项卡,在Environment Variables中增加Name: NSZombieEnabled--》Value:YES、Name: MallocStackLogging--》Value:YES,并点击2个环境变量左侧的复选框,保证在启用状态。
2、debug自己的项目,出现EXC_BAD_ACCESS错误的时候,在控制台会出现类似下面的log
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 instance0x7245470
从最后一行可以看出是调用了已经被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错误
- iOS - EXC_BAD_ACCESS 错误排查
- 如何排查EXC_BAD_ACCESS错误 及内存增加问题
- CSS如何排查错误
- 如何很快定位到EXC_BAD_ACCESS错误
- 如何排查SQL死锁的错误?
- EXC_BAD_ACCESS iOS内存错误
- exc_bad_access错误调试技巧
- EXC_BAD_ACCESS的错误定位
- NSZombieEnabled 解决EXC_BAD_ACCESS错误
- NSZombieEnabled 定位 EXC_BAD_ACCESS 错误
- 打印 EXC_BAD_ACCESS 错误原因
- Thread1:EXC_BAD_ACCESS错误
- ios内存错误 exc_bad_access
- iphone如何调试EXC_BAD_ACCESS
- 如何调试EXC_BAD_ACCESS
- iPhone 如何调试 EXC_BAD_ACCESS
- SQL 语句执行批量替换操作
- 设置文件指针 SetFilePointer SetEndOfFile GetFileType
- 正整数质因数分解
- Android获取手机总内存和可用内存
- Spring Quartz 配置
- 如何排查EXC_BAD_ACCESS错误
- android webView使用方法二
- form 触发器的层次Before、Override、after的区别 .
- 超强JavaScript编辑器webstorm主题(theme)
- 排序算法网址
- 追MM与23种设计模式
- new分配内存
- 使用VBS如何获取本地EXCEL的行和列
- struts2标签属性之disabled 属性