在Instrument-Leaks中,以下代码总是会增加分配内存,当我推动 PhotosObj 。释放 PhotosObj 时无效。
if (PhotosObj) {
[PhotosObj release];
PhotosObj=nil;
PhotosObj=[[Photos alloc]initWithNibName:@"Photos" bundle:nil];
}
else {
PhotosObj=[[Photos alloc]initWithNibName:@"Photos" bundle:nil];
}
[self.navigationController pushViewController:PhotosObj animated:YES];
请澄清我。
先谢谢
答案 0 :(得分:0)
PhotosObj是什么类型的变量?本地,全局或实例变量? 我建议将它变为局部变量(变量名称应以小写字母开头),如下所示:
Photos *photosObj = [[Photos alloc] initWithNibName:@"Photos" bundle:nil];
[self.navigationController pushViewController:photosObj animated:YES];
[photosObj release];