xcode中leaks使用

来源:互联网 发布:江苏省软件检测中心 编辑:程序博客网 时间:2024/05/28 03:03

使用xcode开放app的时候,如果环境是非arc环境,或者使用到了c++进行混编。需要考虑到内存的管理。在此记录xcode中的工具使用,方便日后查看吧。

1,新建一个项目,添加一个按钮,制造一个内存泄露,方便测试使用。

- (IBAction)addbutton:(id)sender {    NSString *str = [[NSString alloc] initWithFormat:@"%ld, %ld," , 100L, -1L];       UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:str message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];    [alerView show];        char *str111 = (char*)malloc(100);    str111[10] = '\n';    printf("%s", str111);        //free(str111);}

2.点击,选择模拟器运行。打开xcode中instruments工具,选择leaks。

3.在选择我们需要测试程序,此处的程序background.

4.选择运行。

5.触发内存泄露,下图红色即为内存泄露。

6.双击,看到内存泄露列表,双击列表一项,就会定位到具体代码。


0 0
原创粉丝点击