收到内存警告的未知原因 [英] Unknown reason to receive Memory Warning

查看:95
本文介绍了收到内存警告的未知原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我快点发布.到目前为止,我的代码没有问题.我唯一关心的是内存管理.让我明确我的应用逻辑.

let me come to issue fast. There is no problem in my code so far. My only concern is Memory management. Let me make my app logic clear.

  1. 在全球范围内启动App时,将声明NSmutableDictionary,并使用pathForResource:ofType方法将近300张具有各种键的图像添加到该Dictionary中.

  1. When App is launched globally NSmutableDictionary is declared and nearly 300 images are added to that Dictionary with various keys and images are added using pathForResource:ofType method.

在我的rootViewController加载后,我的35个自定义UIView用另一个键添加到了相同的全局字典中(此rootViewController不会经常使用)

After my rootViewController loaded my 35 custom UIViews are added to same global dictionary with another key.(this rootViewController will not be used often)

我有4个ViewController,我将使用此UIViews和图像将其用于全局词典中的所有ViewController.

I have 4 ViewControllers where i am going to use this UIViews and images to all ViewControllers from the global dictionary.

我释放视图并将其移到另一个viewController时变为零.

I release the view and making it to nil when moving to another viewController.

我的问题是我在ViewControllers之间快速移动时(1-> 2-> 3-> 4-> 1).如果我这样做4至6次,它就会崩溃.

My issue is when i move between ViewControllers fast ( 1 --> 2 --> 3 --> 4 -->1 ). it gets crashed if I do like this for 4 - 6 times.

如果我缓慢移动,它会在10到15次后崩溃.

If I move slowly it gets crash after 10 - 15 times.

我什至不知道它为什么崩溃的原因,即使我的Live字节最大为5 MB.我从控制台以及从设备日志获得的所有信息都是收到内存"警告.使用仪器时,没有泄漏,没有脏物或居住者的大小.

I Dont know the reason why it gets crashed even my Live bytes is max 5 MB. all i get from console and also from Device log is Received Memory warning. No leaks and No Dirty size or resident size while using Instruments.

在模拟器中运行时,我仅在多个设备上才遇到此问题.

While running in simulator i dont get this issue only on multiple devices i got this issue.

我有以下疑问

  • 在全局字典中添加所有内容是否很好.我的想法是减少每个ViewController的加载时间

  • Whether its good to add everything in global dictionary. My idea is to reduce the loading time for every ViewControllers

我们可以使用pathForResource或以图像命名的方法来重复使用相同的图像.

for reusing same images can we use pathForResource or image named method..

预先感谢...

推荐答案

所以你的问题:

收到内存警告的未知原因

Unknown reason to receive Memory Warning

第一个原因:

在全球范围内启动应用程序时,将声明NSmutableDictionary并 使用各种键将近300张图像添加到该词典,并使用pathForResource:ofType方法添加图像.

When App is launched globally NSmutableDictionary is declared and nearly 300 images are added to that Dictionary with various keys and images are added using pathForResource:ofType method.

第二个原因:

在我的rootViewController加载后,我的 35个自定义UIView被添加到 相同的全局词典,带有另一个键.(此rootViewController 不会经常使用)

After my rootViewController loaded my 35 custom UIViews are added to same global dictionary with another key.(this rootViewController will not be used often)

其他问题:

在全局字典中添加所有内容是否很好.我的想法是 减少每个ViewController的加载时间

Whether its good to add everything in global dictionary. My idea is to reduce the loading time for every ViewControllers

不,不是... 惰性初始化?

为了重用相同的图像,我们可以使用pathForResource或名为 方法.

for reusing same images can we use pathForResource or image named method..

您可以使用所需的任何东西,只要在实际需要时使用它即可.

You can use whatever you want, as long as you use it when you actually need it.

这篇关于收到内存警告的未知原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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