6

This issue never happened to me. I have an UIViewController inside an UINavigationController. When a memory warning is received (nevermind the level), the viewDidUnload method of the visible controller is called, so the view is unloaded and I get an awesome black screen (with a navigation bar at the top).

I'm testing with an iPad 1 on iOS 4.3.3.

Any suggestions?

emenegro
  • 6,901
  • 10
  • 45
  • 68

3 Answers3

1

From what I understand, the viewDidUnload method is called by didRecieveMemoryWarning function in the UIViewController (the super class). Basically iOS gives you couple of warnings and expect to see your memory usage go down. If you continue to ignore these, OS will kill your app.

Sometimes, though, it is critical to keep some views up and running so the way I get around this is to simply override the didRecieveMemoryWarning method and inside it, don't do anything.

Or better yet, check if self is the current view in the self.navigationController.visibleViewController, and if so, don't pass the memory warning call down to [super didRecieveMemoryWarning].

If you are holding image caches or something, just empty those instead.

HTH

dineth
  • 9,822
  • 6
  • 32
  • 39
  • Quick note, iOS6 has changed this behavior now. UIViewController does not automatically call `viewDidUnload` on a memory warning by default anymore. It just calls the `didReceiveMemoryWarning` method and that's it. Only iOS6. – dineth Oct 18 '12 at 05:17
0

According to Apple memory management guidelines when a viewcontroller recieves memory warnings in critical situations it directly calls viewDidUnload so that memory can be managed by releasing the view.

Its actually ios providing chance to purge your temporary data which wil be useful while recreating the view. Since your UIViewCotroller is the root viewcontroller of the navigationcontroller you see oly navigationbar the view gets unloaded.

Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
kaar3k
  • 994
  • 7
  • 15
  • @emenegro See this [link](http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10), section 'Understanding How Views Are Loaded and Unloaded ' **bold** Figure 4-2 **bold** shows how views are unloaded when ViewController receives memory warning.Also its explanation above the figure. – kaar3k Aug 28 '12 at 10:07
  • I saw these docs time ago and I don't see anywhere what is the exceptional situation in wich a visible view can be unloaded. Those docs explains how a view is unloaded and, C&P from steps of unloading cycle: "If the view cannot be safely released (for example, it is visible onscreen)...". So I want to know if it's possible to get a view unloaded while visible, in this case being inside a navigation stack. – emenegro Aug 28 '12 at 11:36
0

You receive viewDidUnload in low memory situation on controllers, where iOS has determined that the views are not longer needed. Remember that Apple made some improvements on the implementations on later versions of iOS, so it might be worse seeing what happens under 5.x. Second you should review your view controller hierarchy.

Bernd Rabe
  • 790
  • 6
  • 23