Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
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;
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
- The provided example code is a slightly adapted version of the code provided in this stackoverflow post.