Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt Memory Deallocation
yaseminyilmaz last edited by
I have a Qt program composed of objects dynamically created. These objects have derived from QObjects but not used parent argument at the constructor caller for example myQObject *mObject = new myQObject();
Does Qt make the memory deallocation while QMainWindow has been closing or should we do delete operations such as C programmer?
Thanks advance for your clarifications and helps,
lgeyer last edited by
If those objects do not have a parent, they won't be deleted automatically.
Jeroentjehome last edited by
Lukas is right indeed, the objects will not be destroyed when classes aren't used anymore. Qt will clear all allocated memory when closing the program if you mean that.
It is bad practice not to use the "parent" object to control the allocation/destruction of class memory. If you start writing larger programs you might even cause memory leaks! When using the new operator without the parent option always destroy the allocated memory. The only exception is the allocation in the Main class. This gets freed when the program closes.