class Data
{
public:
Data()
{
for (int i = 0; i < 1000; i++)
{
int* x = newint;
ints.push_back(x);
}
}
~Data()
{
for (auto it = ints.begin(); it != ints.end(); it++)
{
delete (*it);
}
}
private:
std::vector<int*> ints;
};
int main()
{
std::vector<Data*> datas;
datas.push_back(new Data);
//when I do this, memory isn't freed
datas.erase(datas.end() - 1);
//frees memory when I do this
datas.back()->~Data();
datas.erase(datas.end() - 1);
}
pls help. using task manager to tract memory used/freed.
Never call the destructor manually. I don't know if this is just for testing but don't do it.
Yes, every time you use new you have to use delete. This is still true for STL containers.