[Automotive] QmlLive: Is LiveNodeEngine::RecreateView mode really needed?
martin.kampas at jolla.com
Mon Aug 8 11:17:25 CEST 2016
Yes, due to the caching done by QQmlEngine, no change would be reflected in the view after just unsetting and setting the source again.
For this purpose there is the QQmlEngine::clearComponentCache() API available and it is already used on two places in LiveNodeEngine::recreateView()  (It's use here is redundant though, since the view/engine is already recreated.)
This API has been available already since Qt 4  and since Qt 5.0 a potentially more usefull QQmlEngine::trimComponentCache() exists  which only clears unused entries. The effect of trimComponentCache() after clearing the source with view->setSource(QUrl()) is basically the same as of clearComponentCache() so it needs a bit more sophisticated approach to really profit from using it.
When the QML component being depeloped needs a specialized environment (context properties etc.), recreating view this way cannot be used at all.
Removing the RecreateView mode would allow for more strightforward code. Trying to eliminate memory leaks in LiveNodeEngine is not really easy currently.
I propose to
1) remove the RecreateView mode and only rely on clear/trimComponentCache() (check its effect here )
2) require to set QQmlEngine and make setting QQuickView optional (useless when the QML component instantiates QQuickWindow)
3) only after that fix memory leaks in LiveNodeEngine :)
If you agree I will contribute patches for this.
More information about the Automotive