diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-11-08 15:53:18 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-11-28 15:51:43 +0100 |
commit | 80f1186338bcf8c7d692b4fadfc46531c002c6b0 (patch) | |
tree | 54691e8af27b72eb49c4bec8bf543c1d13612cd3 /src/imports/calendar/qquickcalendarmodel.cpp | |
parent | 0b7358d2d24cc93160f77bac7b210cf83d404c5b (diff) |
Don't delete items we didn't create
Up until this patch, we've always deleted "old" items when a new one is
assigned. For example, the style's implementation of contentItem will
be destroyed here as it is not accessible by the user and is no longer
used:
Button {
contentItem: Item { /* ... */ }
}
This was especially important before the introduction of deferred
execution, as the "default" items would always be created, regardless
of whether the user had overridden it with one of their own items.
By deleting the old items, we free unused resources that would
otherwise persist until application shutdown (calling gc() does not
result in the items being garbage-collected, from my testing).
Although this has largely worked without issues, deleting objects
that weren't created by us in C++ is not supported. User-assigned items
can be created in QML (with JavaScriptOwnership) or C++ (with
CppOwnership), and it is up to the user and/or the QML engine to
manage the lifetime of these items.
After the introduction of deferred execution, it became possible to
skip creation of the default items altogether, meaning that there was
nothing to delete when assigning a new, user-specified item. This
requires that no ids are used in these items, as doing so prevents
deferred execution. Assuming that users avoid using ids in their items,
there should be no unused items that live unnecessarily until
application shutdown. The remaining cases where items do not get
destroyed when they should result from the following:
- Imperative assignments (e.g. assigning an item to a Button's
contentItem in Component.onCompleted). We already encourage
declarative bindings rather than imperative assignments.
- Using ids in items.
Given that these are use cases that we will advise against in the
documentation, it's an acceptable compromise.
[ChangeLog][Important Behavior Changes] Old delegate items (background,
contentItem, etc.) are no longer destroyed, as they are technically
owned by user code. Instead, they are hidden, unparented from the
control (QQuickItem parent, not QObject), and Accessible.ignored is
set to true. This prevents them from being unintentionally visible and
interfering with the accessibility tree when a new delegate item is
set.
Change-Id: I56c39a73dfee989dbe8f8b8bb33aaa187750fdb7
Task-number: QTBUG-72085
Fixes: QTBUG-70144
Fixes: QTBUG-75605
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/imports/calendar/qquickcalendarmodel.cpp')
0 files changed, 0 insertions, 0 deletions