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

编程入门 行业动态 更新时间:2024-10-23 21:25:53
本文介绍了当我的应用收到内存警告时该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

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

本文发布于:2023-11-16 07:38:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602297.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内存

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!