Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-110498

QtMultimedia leaks a lot of memory on Windows when opengl contexts are shared

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P1: Critical
    • None
    • 6.3.2, 6.4.2
    • Multimedia, WebEngine
    • None
    • e.g. Intel NUC 5i3RYH
    • Windows
    • e0197adf8 (dev), 2276c14ac (6.6), 51d93d306 (6.5)

    Description

      I observed a huge memory leak in our production code since we ported to the rewritten QtMultimedia 6.3. I was able to reproduce the issue with a somewhat minimal example. It only affects Windows.

      The important part is, that we use QtMultimedia and QtWebEngineQuick in the same qml application. Calling QtWebEngineQuick::initialize (which enables Shared OpenGL Contexts) leads to severe memory leaks everytime a video is loaded before it starts to play with the Windows media foundation. The allocated memory is obviously not freed, when the next video starts to play.

       

      Now, the minimal code example which reproduces the memory leaks. The call to QtWebEngineQuick::initialize() is necessary. Otherwise the memory leaks do not happen.

      main.cpp: 

      #include <QQmlApplicationEngine>
      #include <QtWebEngineQuick>
      
      int main(int argc, char *argv[])
      {
          QtWebEngineQuick::initialize(); // this is essential !
      
          QGuiApplication a(argc, argv);
          QQuickView view;
          view.setSource(QUrl("qrc:/qml/main.qml"));
          view.show();
      
          return a.exec();
      }

       

      Next, the qml file: the idea is simply to reload the same video once playback has finished:

      main.qml:

      import QtQuick
      import QtMultimedia
      
      Item {
          anchors.fill: parent
      
          MediaPlayer {
              id: mediaPlayer
              source: "file:test.mp4"
              videoOutput: videoOutput
              
              onMediaStatusChanged: status => {
                  if (status === MediaPlayer.EndOfMedia) { // end of video => load next one (or even the same, but be sure to reload source file...)
                      mediaPlayer.source = ""
                      mediaPlayer.source = "file:test.mp4"
                      mediaPlayer.play()
                  }
              }
          }
          VideoOutput {
              id: videoOutput
              anchors.fill: parent
          }
      
          Component.onCompleted: { // first start of play
              mediaPlayer.play()
          }
      }
       

       

      The video (test.mp4 in the working directory) used for testing and debugging purposes is attached!

      The source code of the given example is also attached. Please note, that one must copy the video test.mp4 next to the application binary.

      Furthermore, please find a screenshot of the Windows Task Manager in the attachment. After less than 60sec already more than 1GB additional memory is allocated. The second screenshot was taken after several minutes and the memory already increased to 11,3 GB !

      Unfortunately, it seems to further depend on the hardware. I can observe it on an Intel NUC 5i3RYH for example. But I also tried another Intel NUC (at the moment I do not remember which one, but I could look it up if needed) and the memory leak didn't occur. Most probably it also depends on the video, thats why I attached a simple video for testing purposes.

      This is a big showstopper for us. Please don't hesitate to contact me for further questions.

      Attachments

        1. Screenshot01.png
          Screenshot01.png
          34 kB
        2. Screenshot02.png
          Screenshot02.png
          32 kB
        3. test.mp4
          8.02 MB
        4. videoTest.zip
          1 kB

        Issue Links

          For Gerrit Dashboard: QTBUG-110498
          # Subject Branch Project Status CR V

          Activity

            People

              padubsky Pavel Dubsky
              simeon.kuran Simeon Kuran
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews