Unknown reason to receive Memory Warning
Asked Answered
R

1

1

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

Roue answered 21/3, 2013 at 12:48 Comment(1)
DO NOT use imageNamed Method instead use imageWithContentsOfFile: method. ImageNamed will kill your app and you will be searching for the stars in the day light.. :-/ I hope you are caching images on your device (Cache or other directory).Havre
H
5

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.

Husk answered 21/3, 2013 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.