I am trying to free memory after using QList, but it seems to be working incorrectly. Here is my code:
QList<double> * myList; myList = new QList<double>; double myNumber; cout << "CP1" << endl; getchar(); // checkpoint 1 for (int i=0; i<1000000; i++) { myNumber = i; myList->append(myNumber); cout << myList->size() << endl; } cout << "CP2!" << endl; getchar(); // checkpoint 2 for (int i=999999; i>0; i--) { myList->removeLast(); cout << myList->size() << endl; } cout << "CP3!" << endl; getchar(); // checkpoint 3 delete myList; cout << "CP4!" << endl; getchar(); // checkpoint 4
Memory usage:
- CP1: 460k
- CP2: 19996k
- CP3: 19996k
- CP4: 16088k
So it seems that when deleting items and deleting myList , most of the memory is used. I believe there is a way to handle this, but I cannot find it.
Thanks in advance for your help.
Pawel
source share