didReceiveMemoryWarning麻烦

时间:2011-05-19 18:21:07

标签: iphone objective-c ios4 memory-management memory-leaks

didReceiveMemoryWarning应该包含哪些内容?我没有看到任何可以释放的东西仍在记忆中。我为managedObjectContext设置了一个属性,就是ivars。

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *calendar = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"calendar.png"]style:UIBarButtonItemStyleBordered target:self action:@selector(viewCal)];
    self.navigationItem.rightBarButtonItem = calendar;
    [calendar release];

    UIBarButtonItem *settings = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gears.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(viewSettings)];
    self.navigationItem.leftBarButtonItem = settings;
    [settings release];

    [SHK flushOfflineQueue];
    [self clearNullWorkouts];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

1 个答案:

答案 0 :(得分:2)

什么在SHK中使您成为flushOfflineQueue以及clearNullWorkouts做什么?这些可能是您在didReceiveMemoryWarning期间需要释放的资源。也只是因为didReceiveMemoryWarning触发并不意味着你必须清理任何东西,例如,如果你仍然显示视图,播放正被引用的音频文件等等。当这个被调用你需要释放像未显示的图像,未播放的音频等。调用didReceiveMemoryWarning后,未显示的视图控制器将调用viewDidUnload,您将在此处设置所有IBOutlets / programmatic视图为nil并释放更多内存。 Apple在Memory Management Programming Guide中讨论了这个问题。