I have a “memory management vs user experience” or just a silly question. Let’s imagine a UITabBarController based app with two tabs. While user is in 1st tab, a memory warnings arrives and 2nd tab’s view controller handles didReceiveMemoryWarning. Let’s also assume that 2nd tab has a pushed view controller. Questions:
- is it OK to manually pop VC in 2nd
tab with
popViewControllerAnimated:when
memory warning is issued? - Is it considered a bad UX or bad
mem-mgmt idea? I think the user may
be surprised with what he/she sees
after switching back to 2nd tab, but
if I don’t pop that VC the user will
see just a blank screen. If user taps ‘Back’, 2nd tab VC will reload itself anyway (restart life-cycle withviewDidLoad:and it’s better than the app being killed by iOS).
The only flaw I see in above approach is when my pushed VC also pushed some VC. Then, the code would complicate… and if there was anything else pushed, it would complicate further leaving me with hard to maintain spaghetti code like that:
- (void)didReceiveMemoryWarning {
UIViewController *pushedController = [self.navigationController visibleViewController];
if ([pushedController isKindOfClass:[MyController class]]) {
// POP
[self.navigationController popViewControllerAnimated:NO];
} else {
// MyController pushed something
UIViewController *innerController = [pushedController.navigationController visibleViewController];
if ([innerController isKindOfClass:[MyOtherController class]]) {
[innerController.navigationController popViewControllerAnimated:NO];
// Final POP
[self.navigationController popViewControllerAnimated:NO];
}
}
[super didReceiveMemoryWarning];
}
What’s your approach/advice? Maybe there’s already a simple approach for this and I overlooked it?
Any undefined behaviour would surely mean bad user experience. When your controller gets a memory warning the best approach would be to release any cached images, views(which are not in view), variables(not in use). You may want to design the app in such a way that memory management in the above scenario would not lead to undefined behaviour. Your app may not want to hog up all the memory and not know how to release it.
It should be able to release the unwanted memory and handle the warning. You may want to specify what kind of data you are holding inorder to get a more specific response here.