10

Working on a medium size Qt project we've noticed, that memory consumption is surprisingly high when there is not much going on on the screen. My attempts to find some kind of memleak led me to CREATE_QML_OBJECT macro, where qml instance objects are created. After removing all custom ui elements from loaded qml file and leaving just four basic ones I got

Rectangle {
    Button {}
    CheckBox {}
    Slider {}
    TextField {}
}

And this thing consumes about ~1-1.5 MB.

I've had a look at QtQuick demo projects and its the same thing there:

Gallery demo. Just a bunch of controls, 100 MB on startup.

Same game demo. Simple game, after 5 mins of playing 256MB are gone.

I'm really surprised by the fact that a simple QtQuick QML application can eat enormous amount of memory. Does anybody know what causes this allocations and is there a way to manage it?

Any help will be greatly appreciated.


Related links, haven't found an answer there

QML big memory consumption?

Memory footprint of QML applications

Performance Considerations And Suggestions

vim
  • 454
  • 4
  • 11

1 Answers1

3

Its all managed by javascript garbage collector. Few thing to try are:

1)Call gc() just after loading an item i.e. on Component.onCompleted:

2) Load the items on Loader. This way, they should not stay in memory when not is use.

These do not guarantee reducing memory footprint but can help a bit.

Aman
  • 696
  • 1
  • 8
  • 26
  • Thanks for advice, but it appears that its just how qt quick supposed to work. Apparently high memory footprint was not a concern for the development team. Maybe the idea was that you should implement some small parts of your UI in qml. I would not recommend using qtquick-only for a large project, pure widgets are much more efficient. – vim Dec 23 '14 at 14:24