In a view based app, I display a view and once the user is finished with that view, Done is clicked and the view is removed. However, that does not dealloc the view, which is what I want to do. What is the proper way to dealloc this type of view?
Currently, I’m nil’ing out the second view before it is called. That seems to work and the second view is reinitialized. However, isn’t it more appropriate for the second view to destroy itself (nil itself after removeFromSuperview)?
In first view:
//show next view
aView = nil;
if(aView == nil)
{
aView = [[AView alloc] initWithNibName:@"aView" bundle:nil];
}
[self.view addSubview: aView.view];
Click Done in aView
[self.view removeFromSuperview];
The method
removeFromSuperviewwill automatically release “aView.view”, so you shouldn’t release aView in the first view controller. I think you’ve declaredAView *aViewin head file, but you don’t need to. You may declare the aView as a local variable like this: