title: new operator in function call
body: <p>My question is what happens to the object allocated with the <code>new</code> operator that is inside a function call.</p>
  
  <p>A specific example: I have a private vector <code>pV</code> which I want to send to a object/function outside of the class, <code>foo-&gt;func(std::vector&lt;int&gt; *vec)</code>. I first tried to write</p>
  
  <pre><code>foo-&gt;func( new std::vector&lt;int&gt;(pV) )
  </code></pre>
  
  <p>but this resulted in a memory leak (when said function is called repeatedly inside a loop). When I specifically created a new object, called the function and then deleted that object, the whole thing worked, without the memory leak.</p>
  
  <p>Shouldn't the newly created object 'expire' and be deleted when the function returns? If not, how should I delete the object, from inside the called function? And which is the better approach?</p>