Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-763

addTab()-added widget is not deleted after tab removal when cyclic references to child are present

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.9
    • PySide
    • None
    • Linux/Wayland

    Description

      addTab()-added widget is not deleted right after tab removal when cyclic references to child are present, even when deleteLater was called.

      To reproduce, run the following program and do NOT terminate it, and while it runs, examine the output on the terminal:

      from PySide2 import QtCore, QtGui, QtWidgets
      import time
      
      class OtherWidget(QtWidgets.QWidget):
          def __init__(self, callback):
              super().__init__()
              self.callback = callback  # breaks deletion.
      
      class TabWidget(QtWidgets.QWidget):
          def __init__(self):
              super().__init__()
              l = QtWidgets.QVBoxLayout()
              self.setLayout(l)
              self.other_widget = OtherWidget(self.dummy_func)  # breaks deletion
              l.addWidget(self.other_widget)
              print("TabWidget created.")
      
          def dummy_func(self):
              print("This is me: " + str(self))
      
          def __del__(self):
              print("TabWidget deleted.")
      
      class DocumentTabs(QtWidgets.QTabWidget):
          def __init__(self, style=None, parent=None):
              super().__init__()
              w = TabWidget()
              self.addTab(w, "Test")
              del(w)
              w = self.widget(0)
              self.removeTab(0)
              w.deleteLater()
              print("Tab removal test done.")
      
      class DocumentWindow(QtWidgets.QMainWindow):
          def __init__(self):
              super().__init__()
              self.tabs = DocumentTabs()
              self.setCentralWidget(self.tabs)
      
      qt_app = QtWidgets.QApplication()
      w = DocumentWindow()
      w.show()
      qt_app.exec_()
      
      """
      output:
      
      $ ./bug.py
      TabWidget created.
      Tab removal test done.
      """

       The expected output BEFORE terminating the program would be:

       EXPECTED VARIANT A:

      $ ./bug.py
      TabWidget created.
      Tab removal test done.
      TabWidget deleted.

      or alternatively EXPECTED VARIANT B:

      $ ./bug.py
      TabWidget created.
      TabWidget deleted.
      Tab removal test done.
      

      This bug is a huge issue for me, because I have a tab-based application where all documents are tabs, and this essentially means all python objects for all tabs stay around forever. Since the documents are very memory heavy, this means closing them won't get rid of it, and the application will continue to pile up memory until deleted. (That the tab widgets are finally deleted when the whole TabWidget bar goes away doesn't help me, since that never happens before the program terminates...)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            jirauser48570 user-1fb8f (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes