Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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);
        player1->setText("text001");
        player1->setLogo("logo001.png",0,0);
        grid->addWidget(player1,0,0);
    
        FfmpegPlayer* player2 = new FfmpegPlayer(input1,5,0,2000,320,240,parentWidg);
        player2->setText("text002");
        player2->setLogo("logo002.png",0,0);
        grid->addWidget(player2,0,1);
    
        parentWidg->show();
    

    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 :
    output.png

    (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
    https://www.youtube.com/watch?v=EkauWynyk_8&list=PLL_KGaE_jb1P_0j-0pceOgE7EPt0nx77t&index=1&ab_channel=AlessandroFerraioli

    With QQuickView
    https://www.youtube.com/watch?v=xSrUX25Wt64&list=PLL_KGaE_jb1P_0j-0pceOgE7EPt0nx77t&index=2&ab_channel=AlessandroFerraioli

    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 https://codereview.qt-project.org/q/abc0fc64b3d797af4d47cd2f7e3df68a3114c120


Log in to reply