Unknown reason to receive Memory Warning

南楼画角 提交于 2019-12-11 08:28:04

问题


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. 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.

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

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

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

  5. 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.

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

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.

I have following doubts

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

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

Thanks in advance ...


回答1:


So your question:

Unknown reason to receive Memory Warning

First reason:

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.

Second reason:

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

Other questions:

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

No, it's not... Lazy Initialization?

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.



来源:https://stackoverflow.com/questions/15548033/unknown-reason-to-receive-memory-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!