Why do we need both (void)viewDidUnload and (void)dealloc {
When is a view unloaded and yet not deallocated?
Why do in viewDidUnload we do
self.member = nil;
and in dealloc we do
[member release]
They do alm开发者_如何学JAVAost the same thing but why we do one in viewDidUnload and the other in dealloc?
viewDidUnload get called when your app receive a memory warning. You have to release all retained views that can be reconstructed in loadView or viewDidLoad.
I don't think you should be doing that, as member will be nil
when you send the release
message in your dealloc
method, so the original member
will leak.
viewDidUnload is called when the view is unloaded (hence the name) and is used to unload basically everything you load with loadView oder viewDidLoad to free up memory when memory resources are scarse. The system gives you an opportunity to free up resources that can later be loaded again with viewDidLoad / loadView. Usually, you would free up every visual components or hierarchies you created in viewDidLoad or over the NIB. But you would retain your data and free only resources that cannot get automatically (viewidLoad, loadView or any of your own caching mechanisms) reloaded. In dealloc you release everything that is retained by your class
精彩评论