UIViewController Memory Warning issues
Something odd is happening with my view controllers. When an applicationDidReceiveMemoryWarning is posted, it removes all views from the stack other than the visible view (a second level view) which is expected behaviour. However, if I then navigate back to the root view, it also has a back button that navigates back to itself. From there on the app views behave very oddly to the effect that the app is useless.
More strangely the exact same second-level view (with no memory leaks) can work fine without any memory warnings, yet sometimes on app launch cause a memory warning and therefore the navigation issues. The view holds all the same controls and data as before, yet can sporadically be too much for the device to deal with. I开发者_开发技巧s this something to do with memory available on the device at the time of launch? This only seems to happen on hardware.
Any ideas?
I have found the problem - and it's my code after all.
On application launch I load my root view controller, then in my root view controller's viewDidLoad method I am telling it to load a second view if a condition applies.
When the memory warning occurs, it's recreating the root view controller when exiting the second view, and then creating the second view again whilst still showing the root view.
This then causes the navigation to go mental.
I am by far no expert on memory issues. But odd behaviour after this kind of things indicate to me that the removing of memory did not happen consistently. Maybe some references are still kept and the app thinks these are valid references, but in reality, the memory is no longer allocated. It could also be possible that the memory is reallocated with the old references still in place which could also lead to strange behaviours.
Hm, i can not offer much advice here, only that you could check references to unallocated areas
精彩评论