"john smith" <as**@asdf123asdf.net> wrote in message
news:bh***********@news.eecs.umich.edu...
Hi, when there is a vector<> of pointers to some objects, does calling
resize cause vector to call delete on each object, or is there a memory
leak problem?
for example:
struct base {//some vars; ~base();};
vector<base*> vb;
vb.push_back(new base);
vb.push_back(new base);
vb.push_back(new base);
vb.push_back(new base);
vb.resize(12); // cause memory leak here?
Thanks in advance.
S
You chose a bad example. But vector will *never* call delete on the pointers
you put into it. Think about it, how could vector know that you allocated
the pointers using new? All pointers look the same whether they've been
allocated with new, malloc or not allocated at all.
This is why a vector of pointers is a bad idea (in general). Learn about
smart pointers instead.
john