I have a program in which I collect some data and store them temporarily in a deque
typedef vector<float> floatVector;
...
floatVector * currRecord;
deque<floatVector *> data;
...
...
for (...)
{
...
currRecord = new floatVector(10);
data.push_back(currRecord);
}
Later, I want to save data to file
while (data.size() > 0)
{
for (int i=0; i < 10; i++)
{
fprintf(fPtr, "%lf\t", data[0]->at(i) );
}
fprintf(fPtr,"\n");
data.pop_front();
}
So, my question is, will this program cause a memory leak? I use new
operator to allocate memory for each currRecord
vector. Will the deque pop_front
function automatically recycle memory? Or do I need to put
delete [] data[0]
before
data.pop_front();
? Also, if data
is a vector instead of a deque, will everything be the same? Thanks!