views:

98

answers:

1

I'm running into a situation where didReceiveMemoryWarning is being called but viewDidUnload is not. The docs for didReceiveMemoryWarning say:

The default implementation of this method checks to see if the view controller can safely release its view. This is possible if the view itself does not have a superview and can be reloaded either from a nib file or using a custom loadView method. If the view can be released, this method releases it and calls the viewDidUnload method.

The view controller is not visible at the time but is the parent for a modal that is (usually under a image picker when the memory warning is made). It seems like the view should be able to be released, but maybe I'm missing something.

The reason this matters is that I've been releasing some cached data in didReceiveMemoryWarning on the assumption that viewDidLoad will be called when the view is reloaded. But as viewDidUnload is not being called, neither is viewDidLoad when the view is being shown again...

A: 

The controller's view does have a superview, even when it's hosting a modal view controller (after all, that controller's view ends up as a subview of that of the controller presenting it), and so its view isn't getting unloaded. I'd recommend picking up your cached data again in -viewWillAppearAnimated:.

Noah Witherspoon
You are correct - when I present a modal view controller, superview is not nil. I guess this makes sense (as the navigation controller is pushing, not the view controller itself, while the view controller presents the modal view). I still am not sure I understand exactly what that superview is though.
blindJesse