Question

I have a stack of UIViewControllers currently, each is a modal ViewController presented over the previous one. My problem is that I do not need a stack of UIViewControllers, I only need the last one. So when a new UIViewControllersis presented, its parent should be purged, deleted completely from memory. My app will never need those viewcontrollers again.

I have read this: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html

But this pattern only cares with memory freeing if the app gets a memory warning. And doesn't purge viewcontrollers, only their content. I would like to do it in a more manual manner... Is this possible, or it is not a common practice in iOS, and I should rely only on memory warning messages.

Was it helpful?

Solution

The easiest way is to avoid creating the stack in the first place. Instead of presenting new modal controllers over existing ones, have your root controller dismiss the existing one first and present each new one.

OTHER TIPS

I might have found a nice solution. One should use a UINavigationController, and manage its viewContollers property (which is the stack of UIViewControllers) manually. After (or before) the new UIViewController loaded, you can delete the old UIViewController from the stack, and thus purge it from the memory.

This post helped: How can I pop a view from a UINavigationController and replace it with another in one operation?

This way you can make a program flow, where only when UIViewController is in the memory at a time, and you replace them when you need a new UIViewController.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top