These links should help you do this better :)
http://www.boost.org/doc/l
http://en.wikipedia.org/wi
Main Topics
Browse All TopicsHi,
I have what I think is a very simple question, but since I need a quick definitive answer I'm giving it maximum points.
From C++ documentation II understand that when you have a vector of elements, and call the vector pop_back() or erase() methods, the destructor for the element(s) removed is supposed to be called automatically. If the elements are pointers that were allocated via new(), then should delete() should be called for each element before it is removed from the vector? Is the code below correct? I'm chasing a memory leak/corruption and want to eliminate this possibility. Thanks for any reply!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
These links should help you do this better :)
http://www.boost.org/doc/l
http://en.wikipedia.org/wi
Business Accounts
Answer for Membership
by: evilrixPosted on 2009-08-26 at 08:00:27ID: 25188415
>> the destructor for the element(s) removed is supposed to be called automatically.
If the objects life ends (ie it goes out of scope) yes.
>> If the elements are pointers that were allocated via new(), then should delete()
Yes, heap allocated memory is your responsibility. You can avoid this by using a smart pinter such as the boost:shared_ptr. You CANNOT use std::auto_ptr though as it has move and not reference semantics so it is unsuitable for STL containers.
>> Is the code below correct?
Only took a quick look but it should do what you expect, yes.