• Create Account

### #ActualAlessandro

Posted 03 July 2012 - 05:19 AM

I use std::vector(s) as containers for structs, where I store my data.
Just to make a quick example, I've something like this:

struct myFolliclesLib  {
QString follicleGroupName;
std::vector<myData::myDataLib> myDataIDs;
} ;


Later I store data into the container:

std::vector<myFollicles::myFolliclesLib> myFollicle;
myFollicle.push_back(myFollicles::myFolliclesLib());
...
myFollicle.at(n).follicleGroupName="something";
myFollicle.at(n).myDataIDs.push_back(someData);


Everything works ok, data is stored, I perform queries etc. I've a problem only with deleting and freeing memory.

I thought (after googling around) that deleting the container would just delete also all the data stored inside the structs:

myFollicle.clear();
myFollicle.erase(myFollicle.begin(), myFollicle.end());


Instead, from the Task Manager (I've also another application called Process Explorer that shows memory usage more in detail) the memory is not freed.

So I was wondering wether I need to delete also all the data contained into the structs (and so each vector, array etc.) ?

### #1Alessandro

Posted 03 July 2012 - 05:17 AM

I use std::vector(s) as containers for structs, where I store my data.
Just to make a quick example, I've something like this:

struct myFolliclesLib  {
QString follicleGroupName;
std::vector<myData::myDataLib> myDataIDs;
} ;


Later I store data into the container:

std::vector<myFollicles::myFolliclesLib> myFollicle;
myFollicle.push_back(myFollicles::myFolliclesLib());


Everything works ok, data is stored, I perform queries etc. I've a problem only with deleting and freeing memory.

I thought (after googling around) that deleting the container would just delete also all the data stored inside the structs:

myFollicle.clear();
myFollicle.erase(myFollicle.begin(), myFollicle.end());


Instead, from the Task Manager (I've also another application called Process Explorer that shows memory usage more in detail) the memory is not freed.

So I was wondering wether I need to delete also all the data contained into the structs (and so each vector, array etc.) ?

PARTNERS