首页 技术 正文
技术 2022年11月20日
0 收藏 350 点赞 2,554 浏览 1074 个字

转:http://www.devdiv.com/home.php?mod=space&uid=50901&do=blog&id=50856

在XCode的以前版本中,如果遇到了

[代码]c#/cpp/oc代码:

1 message sent to deallocated instance 0x6d564f0

我们可以使用info malloc-history 0x6d564f0来查看调用堆栈来查看崩溃发生的地方,这种方法这里不作阐述,大家自行百度。

 在新的XCode里,调试器默认使用LLDB,我就讲一下如何在LLDB状态下定位到由于内存操作不当引起的Crash首先我有一段会发生崩溃的代码:

[代码]c#/cpp/oc代码:

1 NSString *themePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:themePathTmp];
2 if(themePath)
3   self.backgroundIV.image = [UIImage imageWithContentsOfFile:[themePath stringByAppendingPathComponent:@"mask_1.png"]];
4    
5 [themePath release];

学过内存管理的人都应该知道在这里themePath并没有被retain,所以如果写了release,那么必然会发生崩溃情况。首先我们需要对开发的环境变量进行设置

如何在LLDB下排查message sent to deallocated instance问题 运行代码,出现下面的崩溃现象如何在LLDB下排查message sent to deallocated instance问题 下面我们打开“活动监视器”,找到我们对应的PID,我们的Target为HPThemeManager,只要找到HPThemeManager对应的PID就可以(HPThemeManager是在论坛里下载的,本来正在看代码,就直接拿他来作试验了)如何在LLDB下排查message sent to deallocated instance问题 现在,我们得到了两个主要的信息:进程ID:50127崩溃地址:0x6d564f0

我们打开终端,输入以下命令:

[代码]c#/cpp/oc代码:

1 sudo malloc_history 50127 0x6d564f0

结果显示为:

如何在LLDB下排查message sent to deallocated instance问题 这样我们用能定位到这行代码

[代码]c#/cpp/oc代码:

1 NSString *themePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:themePathTmp];

对themePath进行排查,就找到了崩溃的罪魁祸首

[代码]c#/cpp/oc代码:

1 [themePath release];

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894