问题
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.
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.
After my rootViewController loaded my 35 custom UIViews are added to same global dictionary with another key.(this rootViewController will not be used often)
I have 4 ViewControllers where i am going to use this UIViews and images to all ViewControllers from the global dictionary.
I release the view and making it to nil when moving to another viewController.
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.
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