Home >Database >Mysql Tutorial >使用Instruments解决EXC_BAD_ACCESS

使用Instruments解决EXC_BAD_ACCESS

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:30:331168browse

http://www.cocoachina.com/bbs/read.php?tid=55526 这里有一篇关于 使用 NSZombieEnabled和MallocStackLogging查找EXC_BAD_ACCESS问题所在的文章。 http://www.cocoachina.com/macdev/objc/2011/0219/2661.html 现在要介绍的其实是为上述方法添加了一个图形

http://www.cocoachina.com/bbs/read.php?tid=55526


这里有一篇关于使用NSZombieEnabled和MallocStackLogging查找EXC_BAD_ACCESS问题所在的文章。
http://www.cocoachina.com/macdev/objc/2011/0219/2661.html

现在要介绍的其实是为上述方法添加了一个图形界面。
错误代码:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Heiti SC Light'}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Heiti SC Light'; min-height: 12.0px}span.Apple-tab-span {white-space:pre}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
NSString* s = [[NSString alloc]initWithString:@"This is a test string"];
s = [s substringFromIndex:[s rangeOfString:@"a"].location];//内存泄露
[s release];
    [self.window makeKeyAndVisible];

    return YES;
}

1.打开Instruments工具,如果XCode是默认路径安装,那路径应该是/Developer/Applications/Instruments.app



2.在弹出的对话框中选中,对应target的Memory / Zombies,选择iOS Simulator(真机好像没有这个选项)



3. 在左上角上选中Choose Target, 然后选择你生成的iphone app程序,一般会在工程文件夹的build/Debug-iphonesimulator下

 



4.点击左上角的record按钮,让程序运行,当程序崩溃的时候会出现一个Zombie Messaged



5.通过分析下方表格的retain和release记录找到问题所在,通过点击Stack Trace可以看到源代码

  



PS:有时候我们可以使用Build an Anlayze功能查找错误。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn