Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved QQUickview generates memory leak

    General and Desktop
    3
    6
    86
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      ferrass95 last edited by ferrass95

      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]

      Pl45m4 1 Reply Last reply Reply Quote 0
      • Pl45m4
        Pl45m4 @ferrass95 last edited by Pl45m4

        @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).


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply Reply Quote 0
        • F
          ferrass95 last edited by

          @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.

          Christian Ehrlicher 1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion @ferrass95 last edited by

            @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.

            Qt has to stay free or it will die.

            F 1 Reply Last reply Reply Quote 0
            • F
              ferrass95 @Christian Ehrlicher last edited by ferrass95

              @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.

              1 Reply Last reply Reply Quote 0
              • Christian Ehrlicher
                Christian Ehrlicher Lifetime Qt Champion last edited by

                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

                Qt has to stay free or it will die.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post