So, so far, I have learned that Qt frees the memory of all child objects when the parent object is deleted. In addition, there is usually no need to worry about memory management for objects created on the stack (i.e. NOT as pointers).
Now that I have done a very good “AddressBook” tutorial , I found this in Part 5:
AddressBook::AddressBook(QWidget *parent) : QWidget(parent)
{
dialog = new FindDialog;
}
Full source available:
addressbook.h
addressbook.cpp
finddialog.h
Here dialogis a private member AddressBook, and he is a pointer to FindDialog. FindDialoginherits QDialog, but no this-Pointer is passed to the constructor (as shown above). There is no explicit destructor, no delete dialog-call ...
Also, non-passing thisseems intentional:
[FindDialog constructor] is defined to accept the parent QWidget, although the dialog will open as a separate window.
Wouldn't that lead to a memory leak? Or is there some other mechanism that silently removes dialogand frees his memory?
Thanks in advance for your help!
Update: . I posted this issue on the qt-project.org forums and it should be fixed soon.
source
share