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

Memory Leak with Images



    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Duplicate
    • Affects Version/s: 5.9.0, 5.9.2
    • Fix Version/s: None
    • Labels:
    • Environment:
      QtQuick 5.9.0, QtQuick 5.9.2, Python 3, Windows 10.


      I am running a webcam image processing script using Python 3 and OpenCV to do some image processing and then send the images to QtQuick via a QQuickImageProvider class to display an video stream to the user. The code runs fine and the GUI and video stream appear normal, but the process has a serious memory leak. It consumes all the available memory before the garbage collector starts cleaning anything up. It appears that even though caching is disabled, the QML is still caching the images, but without any handle or means to access them, so I cannot destroy them manually. I have tried calling the garbage collector for Python and for JavaScript, but neither of these has had any effect on the memory usage, so I am pretty certain that it is an issue with the Image item.

      I have attached a simplified sample of my code to demonstrate the problem, as well as a screenshot of my task manager showing the memory usage. The beginning of the slot is where I started my script and then cliff at the end is where I closed the script. If this were a matter of a few MBs I might attribute it to changes in other processes, but 5 GB is a major memory leak.

      I have tried several workarounds to solve the problem. I tried dynamically creating an Image item for each frame and loading it with a Loader and then destroying it after use, but I could not get that to work. I also tried streaming the images as MPEGs from Python via localhost and using the MediaPlayer and VideoOutput to display it, but the MediaPlayer/VideoOutput could not render the stream. I have tried passing the images to the QML via a slot and drawing it on a canvas, but I could not get that to work either. I have tried just about every workaround that I can think of.

      Is there a known workaround or solution to this problem?


        1. gui.py
          1 kB
        2. main.py
          1 kB
        3. main.qml
          2 kB
        4. memory_usage_from_qtquick_image.PNG
          71 kB
        5. webcam_controller.py
          3 kB

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              srutledg Shawn Rutledge
              loganmackenzie Logan MacKenzie
              2 Vote for this issue
              3 Start watching this issue



                  Gerrit Reviews

                  There are no open Gerrit changes