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

Maybe memory leak in QTreeWidget when removing an item

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 6.5.3, 6.6.1
    • PySide
    • None
    • python 3.8 and 3.11 tested.
    • Linux/X11

    Description

      Trying to remove an item from a QTreeWidget, either using QTreeWidget.getInvisibleRoot().removeItem(top_item) or QTreeWidget.takeTopLevelItem(index) seems to hold the memory. (Note: This issue is not there in a custom build of Qt/PySide 6.3.2)

      However using QTreeWidget.clear() properly releases the memory. Please keep in mind that I would like to keep other top items.

      For now I use a workaround to release the memory: During the removal, I take the top item from my main tree, spawn a dummy tree, attach the top item I want to free to the dummy tree then use the clear() method of this dummy tree. This way the memory hold by the top item is freed somehow.

      I attached a demo script. Running the test creates a 1st top item that I want to keep, then will iterate several times to create and immediately remove a second top item. Those top items are always populated with 3 levels of children so that the memory footprint appears. The memory is never released.

      A checkbox is provided to activate or not the workaround.

      I also put some pympler prints to show the memory consumption before/after the run.

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            afa afa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes