使用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.双击,看到内存泄露列表,双击列表一项,就会定位到具体代码。