iosios5uiviewcontrollerios6viewdidunload

ios5: stopping views from being unloaded / stopping viewDidUnload being called


Given that iOS6 no longer unloads views, and hence no longer calls UIViewController's viewDidUnload, I was wondering if there is a reliable way to cause this same behaviour on iOS5?

That is, I'd really like to stop my views unloading on iOS5, for all the same reasons Apple give for why they no longer unload views on iOS 6 (because it no longer saves any significant amount of memory, and is almost always a source of extra bugs). I'd far rather spend my time developing useful features than testing lots of cases that can now only happen on iOS5 and only in low memory!

I've had a search around and can't find anyone who has asked this question before, which surprises me. Could it just be as simple as retaining an extra reference to self.view in viewDidLoad (and releasing it only in dealloc)? Are there any likely traps?


Solution

  • On iOS5 it is not supported to stop views from unloading and this would also result in a huge memory problem as the way iOS6 handles views is completely different. In iOS6 the backing store of the views is still be removed from memory if necessary - or at least it is marked to be able to be removed from memory. To my knowledge, on iOS5 this isn't the case. The backing store is removed only if the view itself is removed, even if the view itself is only a couple of bytes in size.

    Have a look at this great post: View Controller Lifecycle in iOS 6 This might give you an idea on how complex is, what you are asking for.