当我的应用收到内存警告时该怎么办? [英] What to do when my app receives memory warning?

查看:117
本文介绍了当我的应用收到内存警告时该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序收到内存警告时,我该怎么办?

What should I do when my app recieves a memory warning?

推荐答案

这一切都取决于你的应用程序,通常你不喜欢除了遵循Apple推荐的做法之外,不得不做任何特别的事情。

It all depends on your app, usually you don't have to do anything special except following Apple's recommended practices.

目前看不到的ViewControllers将获得 didReceiveMemoryWarning 消息。默认情况下(调用 [super didReceiveMemoryWarning] )控制器的视图被卸载(释放,释放)。在视图卸载时,视图控制器会收到 viewDidUnload ,您应该在其中释放所有IBOutlet(或以其他方式保留的UI元素)。只有这样才能完全取消分配视图并释放内存。

ViewControllers which are not visible at the moment will get didReceiveMemoryWarning message. By default (calling [super didReceiveMemoryWarning]) controller's view is unloaded (released, freed). As the view is unloading, view controller receives viewDidUnload where you should release all your IBOutlets (or otherwise retained UI elements). Only then the view can completely be deallocated and memory freed.

didReceiveMemoryWarning 中你还应该释放尽可能多的数据你可以 - 如果你在ViewController中存储数据模型的某些部分,释放它,并在 viewDidLoad 中重建,当你再次加载视图时(当用户导航回来时)将调用它到这个控制器)。您也可以通知您的模型类以释放内存。

In the didReceiveMemoryWarning you should also free as much data as you can - if you store some part of data model in ViewController, release it, and reconstruct in viewDidLoad that would be called when your view is loaded again (when user navigates back to this controller). You can inform your model classes to free memory too.

这篇关于当我的应用收到内存警告时该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆