Removing all previously loaded ViewControllers from memory iOS Swift
<p>I am currently editing a code previously written, 
In the application, The first viewController is a table view controller named: ListViewController that has several elements, each selection of row creates a new instance of a view controller and presents it modally. but in those view controllers, instead of dismissing them, the previous developer again created the instance of the ListViewController and presents it modally to go back. </p>

<p>The application is obviously using alot of memory. </p>

<p>Dismissing the view controllers is not an option.</p>

<p>if I pop view controllers in the stack one by one, this doesn't work, each view has popups etc presented on viewdidAppear.</p>

<p>I need to remove all previously loaded ViewControllers from memory and present a viewController such that there are no instances of any ViewControllers left in the memory. 
Is it possible? 
Is there a way i can goto say a new ViewController called HomeViewController ensuring that all previously loaded instances of all view controllers are released. </p>

<p>The scenario is as following:</p>

<pre><code>                         ListViewController 
                     /            |            \ 
             AViewController  BViewController  CViewController
</code></pre>

<p>ListViewController has 3 elements</p>

<p>A
B
C</p>

<p>user can tap any of them, that results in presenting a ViewController.
and from each of the view controllers, when back button is pressed, The ListViewController is presented.</p>

<p>Views are presented using the following code:</p>

<pre><code>if let listViewController = storyboard!.instantiateViewControllerWithIdentifier("ListViewController") as? ListViewController {
                    self.presentViewController(listViewController, animated: true, completion: nil)
                }
</code></pre>