QApplication with QtQuick memory problem



  • Hi, I've got he following problem:

    From beggining: I have an application, which is an QApplication, with QQmlApplicationEngine, the main.cpp file is more less such as the "Qt Quick Controls - table example" from Qt creator. Views are all defined in QML, and the whole main (only) window consist of couple of TableViews components. Application is being developed under windows 7 64bit with MinGw 4.8 32bit and QtCreator 3.0.0 32bit with Qt lib 5.2.0, QtQuick 2.2.

    With no data inserted in TableViews etc. Just with idle app going on, when i resize te window i get massive memory allocation - up to 20MB per resize - which is done by Qt, because my code doesn't do nothing. I tought it may be something connected with repainting etc. But the memory is not freed. As i resize the window or maximize it, the memory usage still grow. When i start app it is about 60MB, and after 10/15 resizes it goes up to 120MB (!). I checked my application with dr.memory on windows, and valgrind on linux - no memory leaks detected...Such behaviour appears both on Windows 7 64bit & Linux (Debian) 32bit. Due to project type I can't share any code of the app, but I can ofcourse describe anything more detailed if needed.

    As i think this example is quite similar to my application - I checked the DEFAULT QtCreator example - which i mentioned above. Qt Quick Controls - Table View Example at startup allocates 66MB (in release session of QtCreator), after resizing the window couple of times(dragging by right-bottom corner) it is 113MB after couple of seconds. AND IT IS NOT DELETED. And it is still growin. I think it is not expected behaviour.

    Maybe anyone had a similar problem? Maybe I'm missing something ? As I'm not sure if it's a bug or maybe I'am doing something wrong, I post it here not in the bugtracker.



  • Memory usage has been discussed before. I think for instance this "thread":https://qt-project.org/forums/viewthread/25855 might be useful.

    I think it is often misleading to look at the current memory usage this way as the garbage collector won't kick in unless it has to. It is clearly a bug if the memory use continues to grow unbounded but I suspect it stabilises at some point.

    If you are looking for possible ways to reduce the initial memory footprint I suspect setting a custom TableViewStyle (or just a custom row delegate) might help a bit as quite a bit of the memory is possibly related to having to resize and re-request pixmaps from the native theme engine during a resize.

    Note that already in 5.3 we have modified the TableView to mostly re-cycle constructed delegates rather than allocating new ones (which should still get garbage collected after a while) and that might possibly make a significant impact on reducing the memory allocations as well as total memory use. Could be interesting to re-run your experiment on the 5.3 beta.



  • Thank You very much for Your response.

    bq. It is clearly a bug if the memory use continues to grow unbounded but I suspect it stabilises at some point bq.

    Memory use stabilises after each resize, but it continoues to grow for each resize event. After 20-30 resizes program uses 320MB. I've waited a minute - to let engine clear the unused memory, but nothing happend. So clearly memory used for window resize procedure is not deleted after it - at least it is what I think so :)

    I will try to run it on 5.3 beta certainly - thanks for information about it. Initial memory is ok, I'm worried only about the resizes. I'll come back to the topic when I'll have information about how it works under 5.3.



  • Hi, I'm using Qt 5.2.1 on windows, mac os x and android and didn't notice any "memory leaks" so far. Just tried your example with resizing the app more than 100 times and I can't confirm any leaks, maybe 5-10 MB difference but it also drops again (when the garbage collectors kicks in I guess).

    How do you measure the used memory? Also be aware of the JavaScript garbage collectors, just waiting a few minutes is no guarantee that i even gets called if your system has enough free memory... but I can't tell you any specifics about the JS engine itself.



  • Hi, thanks for taking your time to reproduce this issue. Thats strange...Are you using Microsoft compiler(VS) or MinGW ?

    I'm just looking at Windows resources monitor and memory usage of my program process.

    Yeah I remember about JS, I also added few explicit calls to Javascript GC, with the
    @gc();@

    I know it is not needed and it shouldn't be done like this - GC is working on its own - nevertheless nothing significant has changed.

    How did you measure used memory (on Windows/Linux)?



  • The app I was testing was compiled with MSVC 2013 (32 bit) on windows and Qt 5.2.0, atm I'm using Qt 5.2.1 with MinGW and have similar results (only the compile process takes forever with MinGW haha).
    I also just looked at the windows resource monitor (you should look at the private memory column i think).

    Are you sure you have no other memory leak in your app maybe?

    You can try and run the QML profiler from Qt Creator and see if you can find something with that, I don't think it shows memory usage but it might still help.



  • Yup that is what I'm doing - private memory in Win. monitor and i get 70MB...80MB...90MB..120MB..140MB..etc...;) I'am pretty shure that there are no leaks, but what more - as i mentioned before - this behaviour also occures in Qt creator "Qt Quick Controls - Table View" example, so I think guys from Qt are pretty far more sure about no memory leaks in their example than even me in my program...

    That is very strange for me, that pulling the right bottom corner of window acts like this.

    Maybe i will try to recompile it under MSVC...
    (i already tried the profiler, but i found no significant information about my problem...)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.