Reputation: 8303
I decided to use storyboards in a project I have been doing. When the app launches it does the right thing of awakeFromNib
and then viewDidLoad
, but when the app has finished segueing to another view, it doesn't call viewDidUnload
and, I think, neither does dealloc. I have used Apple's Instruments and doesn't show any memory leaking.
Just to note, I am using custom segues and testing this by inserting NSLog
s into the methods. Has anyone else come across this?
Just want to update: dealloc
actually is called but not viewDidUnload
.
Upvotes: 0
Views: 787
Reputation: 437381
The viewDidUnload
method is solely for the purposes of didReceiveMemoryWarning
(i.e. when the view is being removed to recover some memory, but the view controller is not). If you want to see viewDidUnload
while running in the Simulator, push or presentViewController to a secondary view, then generate a memory warning from the Simulator's menus. I quote from the UIViewController Class Reference:
When a low-memory condition occurs and the current view controller’s views are not needed, the system may opt to remove those views from memory. [The
viewDidUnload
method] is called after the view controller’s view has been released and is your chance to perform any final cleanup. If your view controller stores separate references to the view or its subviews, you should use this method to release those references. You can also use this method to remove references to any objects that you created to support the view but that are no longer needed now that the view is gone. You should not use this method to release user data or any other information that cannot be easily recreated.At the time this method is called, the view property is nil.
Upvotes: 1
Reputation: 150565
viewDidUnload
is called when the view is actually unloaded. If you want to clean up your resources when the view is not displayed put that in viewDidDisappear
.
If you want to see what is happening with viewDidUnload, run your app in the simulator and from the menubar choose Hardware | Simulate Memory Warning.
Under memory pressure, views that are not on screen are removed and that is when the viewDidUnload
method is sent.
Upvotes: 1