Important: Please read the Qt Code of Conduct -

QQUickview generates memory leak

  • Hi to every one,

    I repost in this section because it might be the right one.
    I'm developing an application whereinto a grid we have different video players ( for the sake of understanding I can tell you that it's a player based on the FFmpeg C++ library).

    We have, as I already said, a grid layout with some players. When I clear the layout, I can see that the memory has been deallocated from the system monitor provided by Linux. So good so far.

    The problem appears when I instantiated for the first time a QQuickView. Let me give you more details: every time it's called the constructor of the QQuickView, even if it's just called for once, and even if the object has been destroyed, the ram stops to be deallocated.

    I can give you a snippet here below :

        //Damn it
        QQuickView view;
        QWidget* parentWidg = new QWidget;
        QGridLayout* grid = new QGridLayout(parentWidg);
       //Creating the players
        FfmpegPlayer* player1 = new FfmpegPlayer(input1,5,0,2000,320,240,parentWidg);
        FfmpegPlayer* player2 = new FfmpegPlayer(input1,5,0,2000,320,240,parentWidg);

    Basically, if I remove the declaration of the QQuickView, everything works fine, and when I press the "clear button" into my player, the memory is deallocated without any kind of problem.
    The opposite seems to happen when I declare the QQuickView and immediately the memory is not deallocated anymore.

    Just wanted to point out that this test-code has been written just for the test, but it actually does the work.

    Does anyone have some tips on how to fix it? I've never faced it before, and it actually sounds really weird. [ I'm using Qt 5.12.5 on Linux]

  • @ferrass95 said in QQUickview generates memory leak:

    QQuickView view;

    Where and how do you use your view? It's unused in the snippet, you've posted above.

    the ram stops to be deallocated

    Are you sure that it is because of the QQuickView? QObjects should clean themselves up together with their parents or at least when they go out of scope (which should be the case here, because it is created on stack).

  • @Pl45m4 Thank you for your answer.

    Yes, as you pointed out, it's unused in this example. The thing is this was just a test to figure out why my application stopped to deallocate memory, and apparently, the problem was the declaration of the QQuickView.

    When I'm saying that the application stops to free the memory, I mean that every time I call the destructor of my FFmpegPlayer, I can clearly see that the level of usage ram doesn't decrease. It's kind of weird, even to explain because it doesn't actually make any sense.
    If I remove the declaration of the QQuickView everything works fine.

    I thought that maybe the constructor of the QQUickview does something weird inside, I genuinely don't know.

  • Lifetime Qt Champion

    @ferrass95 said in QQUickview generates memory leak:

    I can clearly see that the level of usage ram doesn't decrease

    How? Use a proper memory analyzer tool like e.g. valgrind.

  • @Christian-Ehrlicher said in QQUickview generates memory leak:

    @ferrass95 said in QQUickview generates memory leak:

    I can clearly see that the level of usage ram doesn't decrease

    How? Use a proper memory analyzer tool like e.g. Valgrind.

    Yeah, I've done that and this is the Valgrind output :

    (Not sure if posting the image is the smartest thing to do).
    Obviously, If I run Valgrind commenting out line #21(which is the QQuickView), Valgrind doesn't find any kind of memory leak.

    Maybe in this way, I can help you :

    Without QQuickView

    With QQuickView

    As you can see from the first one when I delete the player the ram decrease from 47Mb to 32Mb.

    In the second one, the ram doesn't decrease.

  • Lifetime Qt Champion

    Install libQt5Quick debug info and source to find the exact location of the leak but I would guess it's

Log in to reply