how do i avoid a memory leak when i can't dispose of the data right away
<p>My problem is this, I have an object that I will push into a vector right after I initialize it.  The vector will be used long after the current method goes out of scope.</p>

<p>The code looks like this:</p>

<pre><code>DataObject *ptrDataObj = new DataObject();
Parent::DataVector.push_back(ptrDataObj);
:
:
// end of method
</code></pre>

<p>This implementation will lead to a memory leak for sure.  However, if I use RAII instead of a pointer, the DataObject will have gone out of scope by the time DataVector will use it.  The only alternative I see may involve a copy of some sort.</p>

<p>I've been immersed in C# for many years now and am trying to reacquaint myself in the native world again.</p>

<p>Please advise..</p>
