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

BogDan bog_dan_ro at yahoo.com
Mon Sep 22 10:19:17 CEST 2014


Hi Simon,

I took a look and I'm pretty sure I'm right ;-). BTW I'm using 5.4 
branch (sha1 f9ee33f96), is a little  bit old, but I bet nobody
fixed it. The same problem is in previous releases.

So, the singletons are deleted in QQmlEngine::~QQmlEngine():910
The other active objects are deleted in  MemoryManager::sweep(*true*) 
which is called by MemoryManager::~MemoryManager() 
which is called by ExecutionEngine::~ExecutionEngine()
which is called by QV8Engine::~QV8Engine()
which is called by QJSEngine::~QJSEngine() 
which is called *after* QQmlEngine::~QQmlEngine()

Check the call-stack:
0   MyObject::~MyObject myobject.cpp    44  0x7fffd141eb4b  
1   MyObject::~MyObject myobject.cpp    46  0x7fffd141ec8a  
2   (anonymous namespace)::QObjectDeleter::~QObjectDeleter  qv4qobjectwrapper.cpp   1018    0x7ffff5f79ee1  f9ee33f96f9ee33f96
3   (anonymous namespace)::QObjectDeleter::~QObjectDeleter  qv4qobjectwrapper.cpp   1021    0x7ffff5f79f2e  
4   QV4::MemoryManager::sweep   qv4mm.cpp   377 0x7ffff5efd080  
5   QV4::MemoryManager::~MemoryManager  qv4mm.cpp   515 0x7ffff5efda18  
6   QV4::ExecutionEngine::~ExecutionEngine  qv4engine.cpp   421 0x7ffff5ee4f54  
7   QV8Engine::~QV8Engine   qv8engine.cpp   116 0x7ffff606b7f2  
8   QV8Engine::~QV8Engine   qv8engine.cpp   117 0x7ffff606b87e  
9   QJSEngine::~QJSEngine   qjsengine.cpp   203 0x7ffff5e64b1e  
10  QQmlEngine::~QQmlEngine qqmlengine.cpp  893 0x7ffff5fb0b5d  
11  QQmlEngine::~QQmlEngine qqmlengine.cpp  916 0x7ffff5fb0b8c  
12  QObjectPrivate::deleteChildren  qobject.cpp 1943    0x7ffff599efd0  
13  QObject::~QObject   qobject.cpp 1034    0x7ffff599d760  
14  QWindow::~QWindow   qwindow.cpp 210 0x7ffff63f5bdc  
15  QQuickWindow::~QQuickWindow qquickwindow.cpp    1099    0x7ffff6bc0353  
16  QQuickView::~QQuickView qquickview.cpp  220 0x7ffff6c9fe35  
17  main    main.cpp    12  0x4021fb    

IMHO the sequence from QQmlEngine::~QQmlEngine():910 should be moved
after/in MemoryManager::~MemoryManager ...

Cheers,
BogDan.




________________________________
From: Hausmann Simon <Simon.Hausmann at digia.com>
To: Chris Adams <chris.adams at qinetic.com.au>; BogDan <bog_dan_ro at yahoo.com> 
Cc: Qt Development Group <development at qt-project.org> 
Sent: Monday, September 22, 2014 9:33 AM
Subject: SV: [Development] [QML] Singletons are deleted before the other    objects



Hi,

In gener‎al I agree with Chris. However I'm a little puzzled that this is happening. If you take a look at the QQmlEngine destructor you can see that singletons are deleted last. So I'm wondering what is happening in your app Bogdan. Can you create a minimal test case? 

Thanks,
Simon

Fra: Chris Adams
Sendt: 05:45 mandag 22. september 2014
Til: BogDan
Kopi: Qt Development Group
Emne: Re: [Development] [QML] Singletons are deleted before the other objects 

Hi,



On Fri, Sep 19, 2014 at 10:37 PM, BogDan <bog_dan_ro at yahoo.com> wrote:

Hello folks,
>
>  Singletons registered using qmlRegisterSingletonType, are deleted *before*
>the other active objects. I consider it to be wrong because some of the active
>objects may still need to access the singletons in their destructor ...
>
>IMHO singletons should be the very last objects deleted (also in the reverse
>order).
>

I tend to agree that they should be deleted last.  Enforcing deletion in the reverse
order to how they were registered might impose some slight performance penalty
at instantiation time, however, depending on how the deletion order is determined
at cleanup time, since they are instantiated on demand (and hence possibly
out-of-order).


>Is there any reason why they are deleted before the other active objects?
>Or this is just a bug?
>

I don't believe that there is any particular reason for deleting them prior to other
active objects, but perhaps Simon or Lars can correct me on this point.
Nonetheless, I don't think that the current behaviour is a bug, per-se, as the
destruction order was never documented or guaranteed, as far as I know.

Cheers,
Chris.


>Cheers,
>BogDan.
>
>_______________________________________________
>Development mailing list
>Development at qt-project.org
>http://lists.qt-project.org/mailman/listinfo/development
>



More information about the Development mailing list