Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-60188

Memory leak when aborting QQmlDelegateModel incubation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 5.15
    • 5.8.0, 5.9.0 Beta 1
    • None
    • Tested on Ubuntu and Windows
    • 29fc018b74de3869941438c1f51b3202f93e5198

    Description

      Problem description
      A memory leak occurs when aborting an incubation of QQmlDelegateModel (ex. Repeater). QQDMIncubationTask and QQmlDelegateModelItem are never destructed resulting in a fast memory usage increase for the provided test case. It may be that the problem is more general and concerns all nested incubations, i.e. non empty QQmlIncubatorPrivate::waitingFor.

      Problem analysis
      When you abort a QQDMIncubationTask for a QQmlDelegateModel, the QQmlDelegateModel will be destructed and the QQmlIncubator will be cleared. During destruction of QQmlDelegateModel, all the finished children (m_cache) are destructed, but for the loading items only cacheItem->incubationTask->vdm is set to 0. This seems to correspond with the code in QQDMIncubationTask::statusChanged, which test if vdm exists. If not, it mentions in comment The model was deleted from under our feet, cleanup ourselves and destructs the QQmlDelegateModelItem and the created QObject. However, this code is never reached, because
      all the incubators are already cleared in QQmlIncubatorPrivate::clear.

      Possible solution
      A possible solution is to cancel the incubation of all QQmlDelegateModelItem when destructing QQmlDelegateModel, i.e. replace

      cacheItem->incubationTask->vdm = 0;

      with

      cancel(cacheItem->modelIndex ());

      Another fix is needed to destroy the QQmlContextData of the QQmlDelegateModelItem, i.e. add

      cacheItem->contextData->destroy(); 
      cacheItem->contextData = 0;
      

      before

      delete cacheItem;

      in QQmlDelegateModel::cancel.

      Possible solution v2
      It may be better to implement the deletion in QQmlIncubatorPrivate::clear when the incubators are cleared, but I'm not familiar enough with the internal Qt code to make this judgement.

      Related to

      Attachments

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

        Activity

          People

            srutledg Shawn Rutledge
            m3197d - -
            Votes:
            6 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes