Deleting pointers froms vector?

Hi. I have a vector filled with pointers and I want to delete the pointers. I could do a loop and do delete on all indexes, but my question is that if I just clear the vector. Are the pointers deleted, that is can the memory block that the pointer was pointing to be overwritten?
No, as far as I know
ok/ thanks
What do you mean be delete? doing a loop and calling erase on each element would result in the same memory leak as using the clear member function.

You have to use operator delete if you want the heap memory to be recovered and it must be done for every single pointer stored in the vector. Then you can clear the vector with the clear member function or call erase on each element.
closed account (S6k9GNh0)
http://www.codeguru.com/forum/showthread.php?t=471928
boost::ptr_vector<> is the same as std::vector<> except that boost::ptr_vector<> only stores
pointers-to-T and ptr_vector<> automatically calls delete on any pointer removed from
the container, whether it be from an erase() or a clear().
^So ptr_vector<> is basically like a vector of auto_ptrs?
Yes. (Though of course it isn't really possible to put auto_ptrs in a vector and get any kind of useful semantics).
Topic archived. No new replies allowed.