title: Access Violation in unique_ptr list
body: <p>I've got a <code>list</code> of <code>unique-ptrs</code> which, upon clearing the list, gives the following error:</p>
  
  <pre><code>Unhandled exception at 0x013EA350 in Last.exe: 0xC0000005: Access violation reading location 0xFEEEFEEE.
  </code></pre>
  
  <p>This is triggered in the std::list file, when iterating through the elements. The problem is a little unique:</p>
  
  <ol>
  <li>A <code>MenuManager</code> has a list of <code>unique_ptr&lt;Menu&gt;</code> objects.</li>
  <li>A <code>Menu</code> has a list of <code>unique_ptr&lt;MenuItem&gt;</code> objects.</li>
  <li>The first <code>Menu</code> and all of its <code>MenuItems</code> destruct perfectly, however this error is triggered during the clearing of the second <code>Menu</code> in the <code>MenuManager</code>'s list, with completely independent <code>MenuItems</code>. It appears as if the second <code>unique_ptr&lt;Menu&gt;</code> has become undefined after the destruction of the first, although it was present and non-null at the beginning of the <code>MenuManager</code>'s destruction.</li>
  </ol>
  
  <p>What is causing this? (Not, specifically, where in my code I'm causing this error. I'm wondering what the general cause of this could be)</p>
  
  <p>MenuManager.h</p>
  
  <pre><code>class MenuManager
  {
  public:
      /*MenuManager(list&lt;Menu*&gt; menus) 
          : m_menus(menus) { SetMenu( menus.front() ); }*/
      MenuManager() : m_currentMenu(nullptr) {}
  
  
      // Get the menu that the manager is pointing to.
      Menu* GetCurrentMenu(void) { return m_currentMenu; }
  
      // Set the current menu based on its name.
      void SetMenu(string menuName) { SetMenu( GetMenuByName(menuName) ); }
      // Add a menu to the list of menus managed by this object.
      void AddMenu(Menu* menu);
  
      // Render the current menu.
      void RenderMenu(void) { m_currentMenu-&gt;Render(); }
  
  private:
      list&lt; unique_ptr&lt;Menu&gt; &gt; m_menus; // The list of menus managed by this object
      Menu* m_currentMenu; // A pointer to the menu in current use
  
      Menu* GetMenuByName(string menuName);
      void SetMenu(Menu* menu); // Set the menu based on the menu argument
  };
  </code></pre>
  
  <p><code>Menu</code> is a subclass of another, largely irrelevant class. However, its list is defined as <code>list&lt; unique_ptr&lt;MenuItem&gt; &gt;</code>. <code>MenuItem</code>'s definition is inconsequential.</p>