Memory Handling C++ using Normal Pointer
<p>I have a situation like below in which I have some problem in freeing the memory. Basically I have a vector that holds pointer to objects from classA. I have another classB that store the pointer of classA from the vector. It would make use of the objB. The problem is I need to operate on the vector to erase the pointer. </p>

<p>So how could I free the memory of objA as in the description below?</p>

<ol>
<li><p>pass by value the objA and make a copy in objB?</p></li>
<li><p>delete the pointer to objA in the destructor of objB? ( I would not want to do that as well because it is only when the logic is fulfilled, I need to erase the pointer and delete the object. Otherwise, I would like to keep the object.</p>

<p>vectorA&lt; classA*> vt;
.... storing multiple pointer to objects to vector</p>

<p>classB* objB = new classB(vt.at(pos));</p>

<p>some logic performed. If it is fulfilled, need to erase a particular object from vector.</p>

<p>vt.erase(pos); ==> how do I free the memory if I deleted the pointer here? 
I could not call delete here because objB might need to use the objA later.</p>

<p>classB::classB(classA* objA){
 this->objA = objA;
}</p></li>
</ol>

<p>So there any way to free the memory using Normal pointer as of the case above?
As some of the replies directed me to using smart pointer, my question is are there any penalty imposed on the performance by using smart pointer? (like C# indeterministic garbage collector is not really ideal for performance critical application). </p>
