Clicking the X in the titlebar will send a closeEvent to the window. If the window has a parent, it will be hidden, but not deleted.
To ensure that a parented window is deleted when closed, set the WA_DeleteOnClose flag:
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
This will also recursively delete all child objects of the window.