Why don't some of my view controllers receive the didReceiveMemoryWarning?

The root level view controller in my iPad application is a UISplitViewController. Thus, it has 2 view controllers :

  • one master view controller (item 0 of the viewControllers property)
  • one detail view controller (item 1 of the viewControllers property)

The detail view controller is a custom view controller that I change depending on taps and events in my master view controller.

To change this detail view controller, I use the following code:

- (void)replaceSecondViewControllerBy:(UIViewController *)viewController {
    [[self.viewControllers objectAtIndex:1] dismissModalViewControllerAnimated:NO];
    NSArray *newVC = [NSArray arrayWithObjects:[self.viewControllers objectAtIndex:0], viewController, nil];
    self.viewControllers = newVC;

My problem is that when my app receives a memory warning event, the didReceiveMemoryWarning method is called for all my view controllers, except for former detail view controllers. And they're not being deallocated because they still are delegates for other objects (including asynchronous methods that might still be running).

My questions are :

  • What are the rules for a UIViewController to receive a didReceiveMemoryWarning message ? Why don't my former detail view controllers receive them ?
  • Can I safely call didReceiveMemoryWarning or viewDidUnload myself on these old view controllers ?


It looks like a UIViewController subscribes to UIApplicationDidReceiveMemoryWarningNotification when it is created. It removes observing the notification when it is deallocated. So didReceiveMemoryWarning is called even if the the controller's view is not in the view hierarchy. So make sure your controllers are not deallocated.

It is unlikely but if you happen to be using the following code to remove notification observation from your controllers they will also stop listening memory notifications.

[[NSNotificationCenter defaultCenter] removeObserver:controller name:nil object:nil];

Need Your Help

Line feed (0AH) messing up with video interrupt INT 10H

assembly x86 interrupt

I am trying to write a simply code that uses nested loop, prints the character in the following pattern,

How to evaluate parts of a quoted expression in Emacs Lisp

emacs elisp

Say I have a function that returns a quoted list like so:

SQLite in VS 2012

c# .net database entity-framework sqlite

Ok, spent too much time banging my head with this :)