我試圖在使用QList後釋放內存,但它似乎無法正常工作。 這裏是我的代碼:QList內存釋放
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
內存使用:
- CP1:460K
- CP2:19996k
- CP3:19996k
- CP4:16088k
所以看起來儘管刪除了元素並刪除了myList
仍然使用大部分內存。我相信有辦法處理它,但我找不到它。
在此先感謝您的幫助。
Pawel
看看http://stackoverflow.com/questions/2230618/dynamic-memory-in-qlist – Xorlev
謝謝,但我看起來像我只是做了什麼張貼在一個評論(@格倫) – Moomin