I am still trying to understand the process of managing views when meory warnings occur. I received some good information in this answer, but I still have questions.
Suppose I have a view controller VC1 that contains a subview that is managed by view controller VC2 (which has that subview it's view property). Initially, if I want to put the VC2 view into another the VC1 view, so I might do this:
UIView *VC2 = [UIView alloc] initWithFram...];
VC2.delegate = self;
... // other references to VC2, but not to it's view, yet.
[VC1.view addSubview VC2.view]; // At this point VC2 loadView is called automatically,
// followed by VC2 viewDidLoad.
At some time later, a memory warning is received in VC2. So VC2's didReceiveMemoryWarning is called, followed by VC2's viewDidUnload.
This is where my understanding ends (if what I have already said is correct!)
What I expect to magically happen is that the view in VC2 and its resources can be released (for example, it may be one view that the tab bar controller references, but is currently not being shown), and this should work out alright if it can all be recreated by VC2's viewDidLoad method. Assuming that VC2's view is not vissible for the time being, it should be release.
How, exactly does it get released? The didReceiveMemoryWarning executes in VC2. Does VC2 release its own view? If not, what is suppose to happen.
Second question, if VC2's view has been released, suppose the view is needed again (like someone selectes the corresponding tab on the tab bar). My understanding is that VC2 loadView gets called if view property of VC2 is referenced. Initially it was referenced when VC1 added it as a subview using the property reference. A tab bar controller may call it up by reference through the view controller VC2, which is in the tab bar controller's viewControllers array. So I guess the tab bar controller will reference the view property, and that leads to VC2 loadView being called.
Well I walked through my second question, and may have answered it at the same time. Can someone confirm whether I understand this correctly?
Also, I am still not clear (as in my first question) how and where VC2 view should be released.
Is there a tutorial someone can point me to that walks through this whole process of releasiing views and view hierarchies in response to memory warnings, also expalining how the released views are reconstituted when they are needed? That would really help my understanding of this process.