PDA

View Full Version : How to delete QMap ?



lwz
28th September 2014, 11:06
I have a container like QMap<float, QList<QPair<float,float> *> *> *data, but I can't delete it.
How to solve this problem?

My code :

{
QMapIterator<float, QList<QPair<float,float> *> *> iterator(*data);
while(iterator.hasNext()) {
iterator.next();
QList<QPair<float,float> *> *timeValues = iterator.value();
qDeleteAll(*timeValues);
timeValues->clear();
}
qDeleteAll(*data);
data->clear();
delete data;
data = NULL;
}

but it doesn't work, at least the memory is not given back to OS immediately.

wysota
28th September 2014, 11:50
The memory will not be deallocated from the process immediately, that's a normal thing in modern operating systems.

And why are you keeping a pointer to a QList in the map instead of QList itself?

lwz
28th September 2014, 12:13
Thanks , if I change it to QMap<float, QList<QPair<float,float>>> *data,
Would it be deallocated immediately?

wysota
28th September 2014, 14:38
No, if you change it to 20 year old operating system then maybe it will. But if you remove the pointer from the data structure you will not have to manually delete each value in the map.