didReceiveMemoryWarning 麻烦
我的 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.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SHK 中的什么内容让您需要清除 OfflineQueue 以及clearNullWorkouts 的作用是什么?这些可能是您在
didReceiveMemoryWarning
期间需要释放的资源。另外,仅仅因为didReceiveMemoryWarning
触发并不意味着您必须清理任何内容,例如,如果您仍在显示视图、播放正在引用的音频文件等。当调用此函数时,您需要释放未显示的图像、未播放的音频等内容。调用didReceiveMemoryWarning
后,未显示的视图控制器将调用viewDidUnload
并在这里,您可以将所有 IBOutlet/编程视图设置为 nil 并释放更多内存。 Apple 在 内存管理编程指南。What is in SHK that makes you flushOfflineQueue and what does clearNullWorkouts do? Those may be the kind of resources that you need to free during
didReceiveMemoryWarning
. Also just becausedidReceiveMemoryWarning
fires that does not mean you have to clean up anything, for instance if you are still displaying the view, playing an audio file that is being referenced, etc. When this called you need to release things like images that are not being displayed, audio that is not being played, etc. AfterdidReceiveMemoryWarning
is called view controllers that are not being displayed will haveviewDidUnload
called and that is where you will set all IBOutlets/programmatic views to nil and release more memory. Apple discusses this in the Memory Management Programming Guide.