title: How can I keep a view controller in memory after its popped from the stack?
body: <p>This is an embarrassingly simple question, but I need to preserve a view controller and my current solution is not a solution. </p>
  
  <p>I have a slide out table view menu that lets me select a new view controller to push to the forefront. When I select a view, it deallocs the old main view controller to push the new one. Since 90% of my functionality revolves around one view controller, I want it to stay in memory so I don't have to constantly spend resources to allocate it and either pull the last data source from core data or make a network request. </p>
  
  <p>I naively tried to set a placeholder <code>temporaryMainViewController</code> and assign it to my center view controller before it is assigned another VC, but assigning the current main view controller to the <code>temporaryMainViewController</code> simply assigns the address of the main view controller- so when it's changed, so is my tempVC. 
  Trying to <code>copy</code> the view controller causes a crash.</p>
  
  <p>So how can I effectively do <code>self.temporaryMainViewController = self.currentCenterViewController;</code> where the temp controller is assigned by value of object and not value of address?</p>
  
  <p>-- EDIT --
  More info:</p>
  
  <p><a href="https://github.com/edgecase/ECSlidingViewController" rel="nofollow">ECSlidingViewController</a> keeps (in my case) 3 controllers in memory- the top/center/main view controller, a left hidden controller, and a right hidden controller. My left hidden controller is a tableview, <code>LeftMenuTableViewController</code> , where each row, when selected, observes the view controller class I've associated with that indexPath then instantiates an instance of that class and sets it to the topViewController with a simple assignment statement. I want to keep only my <em>initial</em> top view controller (of class <code>PlacesNavigationViewController</code> (which holds <code>PlacesTableViewController</code>)) in memory when a new view controller is assigned to the top view. </p>
  
  <p>My first approach was to declare a placeholder property in <code>LeftMenuTableViewController</code>, since it never leaves memory itself.</p>
  
  <p><code>@property (nonatomic, strong) UIViewController* temporaryViewController;</code></p>
  
  <p>then in <code>didSelectRowAtIndexPath</code>:</p>
  
  <pre><code>// make local variables for storyboard and the identifier of the view controller that will be pushed, then..
  self.temporaryViewController = self.topViewController;
  self.topViewController = [storyboard instantiateViewControllerWithIdentifier:newViewControllerIdentifier];
  </code></pre>
  
  <p>but this fails because the temporary controller is assigned the memory address of the topViewController- which in the next line is given a new view controller to hold. </p>
  
  <p>So what I need is a way to hold the contents of <code>topViewController</code> so that when <code>topViewController</code> changes, I still have the old VC in memory. </p>
  
  <p>I'm likely forgetting some obvious tenet of Objective-C, but this is giving a good bit of trouble. Let me know if I did not make something clear. </p>