Reputation: 1586
Within my main viewController I have two ivars declared as follows:
UIPopoverController* __popoverController;
HPSQuestionnaireEditorController* _questionnaireEditorController;
I then show a UIPopOver as follows:
_questionnaireEditorController = [ [ HPSQuestionnaireEditorController alloc ] initWithNibName:nil bundle:nil ];
__popoverController.delegate = self;
[__popoverController setPopoverContentSize:CGSizeMake(400, 500)];
[_questionnaireEditorController setContentSizeForViewInPopover:CGSizeMake(400, 500)];
[__popoverController presentPopoverFromRect:editWrapper.frame inView:editWrapper.superview permittedArrowDirections:UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight animated:YES ];
When the time comes to dismiss the popover I do this manually as follows:
[__popoverController dismissPopoverAnimated:YES ];
__popoverController = nil;
_questionnaireEditorController.view=nil;
_questionnaireEditorController=nil;
I am using ARC.
Within the _questionnaireEditorController I have the following:
- (void)viewWillUnload
{
NSLog(@"HPSQuestionnaireEditorController viewWillUnload starting");
}
However, this never runs. The popover dismissal does not appear to actually unload the view or the controller hosted within it.
What am I doing wrong? Thanks.
Upvotes: 1
Views: 296
Reputation: 857
viewWillUnload (and viewDidUnload) are not necessarily called when your view controller is deallocated--they're generally only called in response to a memory warning. According to the UIViewController reference, in the descriptions of both methods:
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.
If there is any essential cleanup, do it in dealloc. If the cleanup just consists of setting retained properties to nil and you're using ARC, you don't need to bother with dealloc.
Upvotes: 1
Reputation: 18551
You're not doing anything wrong. UINavigationControllers, UIPopoverControllers, and UITabBarControllers don't necessary unload your view right when its off screen. They have caching backends that hold on to them until its absolutely unnecessary or they need the memory.
If you don't NEED it to unload then you will be fine. Don't worry about it.
Upvotes: 1