title: C++ vector of pointers, vector declaration and deletion of pointers
body: <p>Let's assume I have a singleton class:</p>
  
  <pre><code>class Singleton {
  public:
      static Singleton* getInstance();
      void doit();
      std::vector&lt;Object*&gt;&amp; getVector();
  
  private:
      std::vector&lt;Object*&gt; _vector;
      static Singleton *instance;
      Singleton();
      ~Singleton();
      Singleton(const Singleton&amp;);
  };
  
  class Delegator {
  public:
          void main();
  }
  </code></pre>
  
  <ul>
  <li>In the <code>doit</code> method I populate the <code>_vector</code> with pointers to objects.</li>
  <li>In the <code>main()</code> from the <code>Delegator</code> class, I call <code>getVector()</code> and display the results.</li>
  </ul>
  
  <p>Given this abstraction, I have the following questions:</p>
  
  <ol>
  <li>Can I delete all the pointers to instances of Object in the <code>main()</code> from <code>Delegator</code> (after displaying the results). If yes, is this recommended? </li>
  <li>Does the singleton ever get destroyed? In other words, will the reference returned in <code>getVector()</code> always be valid? </li>
  <li>I return a reference to a vector instead of a copy of the vector in <code>getVector()</code>. Given that the vector only contains pointers to objects and will not modify the vector content outside the <code>Singleton</code> class, is there any efficiency gained from returning a reference? </li>
  </ol>
  
  <p>Thank you in advance</p>