views:

37

answers:

1

There are times when didReceiveMemoryWarning gets called, but viewDidUnload does not. In my situation I would like to force viewDidUnload when didReceiveMemoryWarning gets called.

I can say this:

[self viewDidUnload];

But will that really unload the views? There is no self "unloadView".

+2  A: 

Why would you want to do this? As long as you remember to call [super didReceiveMemoryWarning] (assuming you implement the method at all), UIViewController automatically unloads its view if its view has no superview. If this process does not happen, that generally indicates that the view is still part of a view hierarchy and it's not safe to unload.

In the rather unlikely case that you really do need to manually unload a view, you can do so simply by saying self.view = nil.

Kevin Ballard
self.view does indeed unload the view, but how can you get it back?
sol
`self.view = nil` unloads it. The next time anyone calls `self.view` it'll be re-loaded. Note, this means don't call `self.view` unless you really want the view to be loaded. You can use `[self isViewLoaded]` before calling that to avoid reloading the view in places where you'd prefer it to stay unloaded.
Kevin Ballard