Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is didReceiveMemoryWarning / viewDidUnload called when a view controller is shown?

A question about didReceiveMemoryWarning / viewDidUnload.

If my app has many view controllers, one of them is shown, and the others back (because of I use a navigation controller or tab bar controller, it does not matter), which view controllers will receive didReceiveMemoryWarning / viewDidUnload, all of them, only hidden, or only shown?

Is it possible that shown VC receives didReceiveMemoryWarning but not viewDidUnload (because as is shown, it doesn't make any sense).

By the way, I have these questions after seeing this diagram: UIViewController init/dealloc flow chart

Thanks a lot for help.

like image 767
Ricardo Avatar asked Nov 14 '22 10:11

Ricardo


1 Answers

First, there are two methods didReceiveMemwarnings:

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application

is called when the application receives a memory warning from the system. and UIViewController's

- (void)didReceiveMemoryWarning

Sent to the view controller when the application receives a memory warning.

Second, firstly is called the code in these methods(well, of course), then in those controllers which don't have superviews(i.e those which are not displayed at the moment) the view is deleted and viewDidUnload is sent

like image 167
Stas Avatar answered Dec 21 '22 05:12

Stas