Memory leakage and memory management
-
I would like devs here to suggest me topics that i should read for learning Qt's memory management mechanism.And look at this aap given below,will this aap delete the reserved memory for mainWindow when no reference is left or it will not do it automatically.If yes why?,if no again why?
@#include <QtGui>
#include <QApplication>int main (int argc,char *argv[])
{QApplication qaap(argc,argv);
QMainWindow *mainWindow = new QMainWindow;
mainWindow->show();
return qaap.exec();
}@
-
As the application ends, it will release the memory which was allocated in line 9. But that's just because it's the normal cleanup that an application does when it exits. Nothing Qt-specific.
You could just as easily do a standard C++ new like:
@
int *foo = new int[1000];
@and while it would be most proper to delete[] the memory when you were done, if it were still in existence when the app exited, it would be released by the OS as the program ended.
-
ok that is clear but i wanted to say that let it be like this if i am using a mainWindow in an aap and doing some other stuff to or you can say i am using the mainWindow in this aap for example
@int main (int argc,char *argv[])
{QApplication qaap(argc,argv);
QMainWindow *mainWindow = new QMainWindow;
mainWindow->show();
//for example doing some network related stuff with values taken from the mainWindow
// and main window is no longer needed.so right here what will qt do will it delete the mainWindow
// pointer itself or not
return qaap.exec();}@