I have following code which I created to check how memory can allocate and free using using qt and c++
Platform: Linux, Ubunut 16.04
testmemeory.h
#include <QObject>
class testMemeory : public QObject
{
Q_OBJECT
public:
explicit testMemeory(QObject *parent = nullptr);
void freeMEm();
char* str;
};
testmemeory.cpp
testMemeory::testMemeory(QObject *parent) : QObject(parent)
{
str = new char [30000];
}
void testMemeory::freeMEm(){
delete [] str;
}
This is the array I used to store the object.
std::vector<testMemeory*> testList;
And I am allocating the memory using
void MainWindow::allocateMemory()
{
for(int i=0;i<50000;i++){
testMemeory *t = new testMemeory();
testList.push_back(t);
}
qDebug()<<"Memory allocated..";
}
And releasing memory using
void MainWindow::relaseMemory()
{
for(int i=0;i<testList.size();i++)
testList.at(i)->freeMEm();
qDeleteAll(testList);
testList.clear();
qDebug()<<"Memory freed..";
}
When I excute allocate memory the RAM used for the application increased from 150MB to about 350MB where as if call relaseMemory() function the RAM is still 350 MB and it not reducing to 150 MB
What could be the reason.