【发布时间】:2011-04-01 08:56:36
【问题描述】:
快速提问,Instruments 报告这里有泄漏...
MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"myView" bundle:nil];
[self.navigationController pushViewController:myVC animated:YES]; //<<<<---- !00% leak according to Instruments
[myVC release];
我知道 myVC 由导航控制器保留,所以我假设导航控制器在视图从导航堆栈中弹出时释放它们?
另外,在我的一个循环中还有一个棘手的问题,静态分析器在这里报告潜在的泄漏......
//Walk through the scheduled alarms and create notifications
NSMutableArray *fireDates = [[NSMutableArray alloc] init];
for(NSDate *fireDate in fireDates) //<<<<---- Static analyzer is reporting potential leak here
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
{
[fireDates release];
return;
}
localNotif.fireDate = fireDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [NSString stringWithFormat:@"%@", alarm.Label];
localNotif.alertAction = NSLocalizedString(@"Launch", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.userInfo = infoDict;
localNotif.repeatInterval = NSWeekCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
}
[fireDates release];
我需要以某种方式释放 fireDate 吗?
提前感谢您的帮助!
【问题讨论】:
-
静态分析器一般都很好...也许不要省略缺少的代码...
-
谢谢,Eiko,我刚刚更新了我的问题以包含缺失的代码。你的想法?
-
您是针对模拟器还是设备运行测试?我注意到,针对模拟器,泄漏程序显示错误泄漏。
-
@joo - 我正在对模拟器进行测试。我会在我的设备上试试,谢谢。
-
@joo - 我在设备上试过了,同样的导航控制器泄漏仍然被捕获。你的想法?
标签: iphone ipad memory-management ios instruments