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

Sticky forms in php zodiac calculator

php html forms sticky

I have a program that when you submit your name and birth day, month, and year it calculates your zodiac sign. I want it so that if you don't submit one piece of info and see the error messages, wh...

js recursion - not works

javascript recursion

I have structure of folders and files as following:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.