Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clean up after "erase ()"

Status
Not open for further replies.

butthead

Programmer
Feb 24, 2002
545
US
I ceate an object with "new".
I add this to a vector using "push_back ()".
I remove the object with "erase ()".

question
does erase do the delete stuff to clean up the trash,
or do I have to do it myself.

thanks in advance.

tomcruz.net
 
push_back() copies the object to the vector, and erase() removes the copy from the vector. So yes, you will have to delete the original object.
 
so this is the corrrect way to clean up the memory.
Code:
table = TableArray [x];
TableArray.erase(TableArray.begin() + x);
delete table;

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top