[Development] [QML] Singletons are deleted before the other objects
Harri Porten
porten at froglogic.com
Mon Sep 29 16:16:05 CEST 2014
On Mon, 29 Sep 2014, Simon Hausmann wrote:
> Yes, with emphasis on "until". Note that we are now talking about the "end of
> the application" situation, so our agreement ends right there ;-). We are
> talking about the time the QQmlEngine destructor is executed, which from a QML
> engine perspective is the "end of the application" point of time. What happens
> during that period of time is just as "fishy" as when tearing down a C++
> application: The order of destruction for global objects between several
> compilation units is undefined. In C++ you cannot rely on it (I think you can
> rely on the order within a unit), so you prepare yourself with levels of
> indirection and/or weak references.
I was thinking the same for a long time. Until I discovered (the hard way)
a that at least one aspect of the C++ behavior is standardized: the order
of destruction is guaranteed to be the reverse of the construction (see
[basic.start.term]).
I ran into this because of a singleton being encapsuled within a function
using a 'static' object. The crashes upon application exit seemed
arbitrary at first but turned out to be well-defined :)
Which deletion order is the best for QML... maybe it can't be changed
anymore. I'd just generally vouch for a *defined* order (even if
problematic) rather than an undefined one.
Harri.
More information about the Development
mailing list