[Development] [QML] Singletons are deleted before the other objects

Simon Hausmann simon.hausmann at digia.com
Mon Sep 29 17:09:19 CEST 2014


On Monday, September 29, 2014 04:16:05 PM Harri Porten wrote:
> 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.

Right, that makes sense. In C++ the problem stems from the diversity of 
compilers, which we (unfortunately :) don't have with Qml. There is only one 
implementation and it defines the behavior.

The question is how much we want to change the behavior. We could implement
a reverse order destruction, if somebody makes a good case for it.

Simon



More information about the Development mailing list