iPhone - Should I manually release my customViewController's view in its dealloc method?
I'm using a navigation controller to push a custom viewController onto the screen. When I'm done and pop it off, I find开发者_开发知识库 that the dealloc method is called for the customViewController, but the "viewDidUnload" method is never called. Does this mean that the view is still there? This could be a memory problem for me if so. If this is the case, should I then release the view in my dealloc method in my customViewContoller? Thanks.
This isn't necessary. When your UIViewController
subclass receives -dealloc
, you should be releasing any retained properties. It will then get to [super dealloc]
. Can't speak with certainty, but -dealloc
on UIViewController should handle dumping all of it's retained properties as well. Thus your view will be released appropriately.
Not sure why -viewDidUnload
isn't getting called, but it shouldn't matter. Perhaps if your app's memory pressure was lower when you pop the view controller, the view may get unloaded without deallocating the entire controller.
Typically you release the view controller after you push it. For example:
UIViewController *myVC = [[UIViewController alloc] init];
[[self navigationController] pushViewController:myVC animated:YES];
[myVC release];
精彩评论