9

Head's up: This question is related to the recent deprecation of viewDidUnload. I have seen "great" and logical answers around this topic, but apparently they were proven wrong. Proceed with caution, this topic is very confusing as you see.

From Apple's Docs:

However, the system automatically releases these expensive resources when the view is not attached to a window. The remaining memory used by most views is small enough that it is not worth it for the system to automatically purge and recreate the view hierarchy.

So... Can I safely assume in iOS 6 that, as long as I don't explicitly set the viewController's view to nil (unload it manually), viewDidLoad will only be called only once for any allocated viewController instance throughout the lifetime of the application?

Community
  • 1
  • 1
Mazyod
  • 22,319
  • 10
  • 92
  • 157
  • 2
    I found that in iOS 6, viewDidLoad would be called twice when I set the ViewController's orientation to landscape. – DJean Nov 28 '12 at 09:25
  • @DJean I believe your answer is more accurate than the current accepted answer. – Mazyod Sep 08 '13 at 21:49
  • @DJean how do you "set" a `UIViewController`s orientation to landscape? Programmatically? When I do it by rotating the device, either manually or [programmatically](http://stackoverflow.com/a/20987296/242933), `viewDidLoad` isn't called again. – ma11hew28 Nov 12 '14 at 17:06

1 Answers1

7

As of iOS 6, your UIViewController subclass will only receive viewDidLoad once, unless you write code to set its view back to nil.

However, I wouldn't rely on that behavior in a complex system-provided view controller like UIImagePickerController. Perhaps it sets its own view back to nil.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848