Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Memory not released when multiple Image is loaded continuously
Forum Update on Monday, May 27th 2025

Memory not released when multiple Image is loaded continuously

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
29 Posts 7 Posters 2.9k Views
  • 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.
  • A Offline
    A Offline
    AdarshKale
    wrote on last edited by
    #1

    Facing Memory leak issue when we load the image source with a sequence of images over a period of time.
    The Memory accumulated for Image loading is never freed.

    Tried with unloading (by setting source = "") every time before loading new image.
    Tried to disable the cache for the Image component.

    Any better solution for clearing the memory?

    Ronel_qtmasterR 1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      Qt is caching pixmaps, that’s why the usage grows.
      That’s not a memory leak.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • A AdarshKale

        Facing Memory leak issue when we load the image source with a sequence of images over a period of time.
        The Memory accumulated for Image loading is never freed.

        Tried with unloading (by setting source = "") every time before loading new image.
        Tried to disable the cache for the Image component.

        Any better solution for clearing the memory?

        Ronel_qtmasterR Offline
        Ronel_qtmasterR Offline
        Ronel_qtmaster
        wrote on last edited by
        #3

        @AdarshKale I only now how to free memory from C++ side;
        After using a QImage in c++ side , to free the image in memory you can do:
        QImage image ;//the image you are working with
        image = QImage(); // you free the memory occupied by the image
        Maybe there's a way of porting qimage to Qml and use it.Hope it helps

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          That doesn’t clear the cache.
          If no caching is needed/wanted, set the cache property to false.

          Software Engineer
          The Qt Company, Oslo

          A 1 Reply Last reply
          1
          • Axel SpoerlA Axel Spoerl

            That doesn’t clear the cache.
            If no caching is needed/wanted, set the cache property to false.

            A Offline
            A Offline
            AdarshKale
            wrote on last edited by
            #5

            @Axel-Spoerl Hello,
            I have already tried setting the cache to false. still, I could see that the memory kept increasing.
            Is there any way to stop caching the pixmaps?

            1 Reply Last reply
            0
            • Axel SpoerlA Offline
              Axel SpoerlA Offline
              Axel Spoerl
              Moderators
              wrote on last edited by
              #6

              Let’s ask the question the other way round: why is it a problem? What’s bad about caching pixmaps and images? And why don’t you just read the related documentation?

              Software Engineer
              The Qt Company, Oslo

              A 1 Reply Last reply
              0
              • gfxxG Offline
                gfxxG Offline
                gfxx
                wrote on last edited by
                #7

                why not use opencv for load image and only after qimage or qml code .... on opencv you can "free" or "clear" at every cicle ..... any how you are sure after usage you clear qimage? maybe, if a loop, there are something of wrong. After load qimage you can show and in row after clear ..... so no buffer ..... better is you declare the same qimage name at every cicle ..... as void var and not a global one for example.

                bkt

                1 Reply Last reply
                0
                • Axel SpoerlA Axel Spoerl

                  Let’s ask the question the other way round: why is it a problem? What’s bad about caching pixmaps and images? And why don’t you just read the related documentation?

                  A Offline
                  A Offline
                  AdarshKale
                  wrote on last edited by
                  #8

                  @Axel-Spoerl
                  To provide you with the background of the problem: This is for an infotainment project
                  I am developing the animation for a Wheel rotation, based on the wheel angle,

                  As and when the wheel angle changes, I need to show the axle movement in terms of animation from the old angle to the new angle,
                  To achieve this, for a smoother animation, we have decided to show a sequence of images with a Timer (We have around 50 images from extreme left to extreme right).

                  When the angle changes from 10 degrees to 20 degrees, we show the sequence of images every 100ms from 10 to 20 (some 10 images).

                  Here Image component is used in QML.

                  property int wheelValue:0
                  
                  Image
                          {
                              id:itm_wheel
                              source: "Wheel_0"+wheelValue+".png"
                              cache: false // even tried enabling the cache.
                          }
                  
                  // wheelValue is updated via Timer 
                   Timer
                      {
                          id: wheelTimer
                          repeat: true
                          running: false
                          interval: 100
                          onTriggered:
                          {
                                  // Some logic to monitor the wheel angle and update the wheelValue
                                  wheelValue+=1
                                  wheelTimer.restart() // until the actual wheel angle is met.
                                 
                                  // Stop the timer when the actual wheel value is met.
                                    wheelTimer.stop()
                             }
                      }
                  

                  We have only 512 MB of memory available,
                  Each asset .png used for this animation is some 10kb.

                  When we keep the animation for some 30 minutes with random updates in wheel angle, we see the accumulation of memory which is never getting freed.

                  Hence we need some way to implement this without accumulating memory.
                  Thanks

                  1 Reply Last reply
                  0
                  • Axel SpoerlA Offline
                    Axel SpoerlA Offline
                    Axel Spoerl
                    Moderators
                    wrote on last edited by Axel Spoerl
                    #9

                    Let's maybe take one step back.

                    a) Memory leak
                    There is no memory leak.

                    b) Use case
                    Are we really sure, that all pixmaps / images are really used only once?
                    Which operating system is used? How about e.g. the XCB backing store? What happens, if a displayed image is covered / uncovered by other screen assets? Do you really wanna re-render in that case?
                    Why is caching a problem at all?
                    Do we not have enough memory?

                    Edit:
                    Sorry, our messages have crossed.
                    If you want to show a total of 50 different images and have smooth movements, 512MB of RAM is probably too little.
                    I'd try it out on a host with sufficient RAM and see what's the minimum required memory.
                    Maybe reducing the images in size and number helps.

                    Software Engineer
                    The Qt Company, Oslo

                    A 1 Reply Last reply
                    1
                    • Axel SpoerlA Axel Spoerl

                      Let's maybe take one step back.

                      a) Memory leak
                      There is no memory leak.

                      b) Use case
                      Are we really sure, that all pixmaps / images are really used only once?
                      Which operating system is used? How about e.g. the XCB backing store? What happens, if a displayed image is covered / uncovered by other screen assets? Do you really wanna re-render in that case?
                      Why is caching a problem at all?
                      Do we not have enough memory?

                      Edit:
                      Sorry, our messages have crossed.
                      If you want to show a total of 50 different images and have smooth movements, 512MB of RAM is probably too little.
                      I'd try it out on a host with sufficient RAM and see what's the minimum required memory.
                      Maybe reducing the images in size and number helps.

                      A Offline
                      A Offline
                      AdarshKale
                      wrote on last edited by
                      #10

                      @Axel-Spoerl said in Memory not released when multiple Image is loaded continuously:

                      b) Use case
                      Are we really sure, that all pixmaps / images are really used only once?

                      we may come across the same image again during the same angle received.

                      Which operating system is used?

                      QNX

                      How about e.g. the XCB backing store? What happens, if a displayed image is covered / uncovered by other screen assets? Do you really wanna re-render in that case?

                      We are handing the visibleChanged property from QML to stop the animation if it is not on that screen.
                      Directly we render the exact Image for the current position then when this screen is rendered.

                      Why is caching a problem at all?
                      Do we not have enough memory?

                      We don't have enough memory.

                      Edit:
                      If you want to show a total of 50 different images and have smooth movements, 512MB of RAM is probably too little.
                      Maybe reducing the images in size and number helps.

                      Reducing the images would not solve the issue, but it postpones it.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        AdarshKale
                        wrote on last edited by AdarshKale
                        #11

                        Need a clean way to not accumulate the memory on every reload of the QML Image

                        1 Reply Last reply
                        0
                        • Axel SpoerlA Offline
                          Axel SpoerlA Offline
                          Axel Spoerl
                          Moderators
                          wrote on last edited by
                          #12

                          One step back again: What's the problem? The cache should resize, if the application runs out of memory. Does your application crash?

                          Software Engineer
                          The Qt Company, Oslo

                          A 1 Reply Last reply
                          0
                          • Axel SpoerlA Axel Spoerl

                            One step back again: What's the problem? The cache should resize, if the application runs out of memory. Does your application crash?

                            A Offline
                            A Offline
                            AdarshKale
                            wrote on last edited by AdarshKale
                            #13

                            @Axel-Spoerl said in Memory not released when multiple Image is loaded continuously:
                            **The cache should resize

                            I don't see the cache getting resized.
                            if I run the top command and perform a script to continuously run the angle change,
                            I get the memory utilized increased - leading to low memory, once the memory reaches below 15MB or so, the System Hangs, and after few seconds application crashes.

                            Even if we come out of that screen during the update, the memory utilisation stops and is never freed.

                            1 Reply Last reply
                            0
                            • Axel SpoerlA Offline
                              Axel SpoerlA Offline
                              Axel Spoerl
                              Moderators
                              wrote on last edited by
                              #14

                              Which Qt version are you using?

                              Software Engineer
                              The Qt Company, Oslo

                              A 1 Reply Last reply
                              0
                              • Axel SpoerlA Axel Spoerl

                                Which Qt version are you using?

                                A Offline
                                A Offline
                                AdarshKale
                                wrote on last edited by
                                #15

                                @Axel-Spoerl said in Memory not released when multiple Image is loaded continuously:

                                Which Qt version are you using?

                                5.15

                                1 Reply Last reply
                                0
                                • Axel SpoerlA Offline
                                  Axel SpoerlA Offline
                                  Axel Spoerl
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  That explains a lot. Outdated version. There is a memory leak in the quick pixmap cache, and it won't be fixed.
                                  Upgrade to Qt 6.7.

                                  Software Engineer
                                  The Qt Company, Oslo

                                  1 Reply Last reply
                                  1
                                  • A Offline
                                    A Offline
                                    AdarshKale
                                    wrote on last edited by AdarshKale
                                    #17

                                    However, we cannot upgrade to newer Qt versions at this stage of the project.
                                    Is there any other way possible?

                                    There should be some workaround to clear the accumulated memory.?

                                    1 Reply Last reply
                                    0
                                    • Axel SpoerlA Offline
                                      Axel SpoerlA Offline
                                      Axel Spoerl
                                      Moderators
                                      wrote on last edited by Axel Spoerl
                                      #18

                                      Qt 5.15 is an outdated Qt version. Given the simplicity of the project, cannot sound more like don't want to.
                                      There is no other way possible and a workaround for 5.15 will not be implemented.

                                      Software Engineer
                                      The Qt Company, Oslo

                                      GrecKoG 1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        AdarshKale
                                        wrote on last edited by AdarshKale
                                        #19

                                        There are a few deprecated APIs used and many syntax changes if we upgrade to the latest 6.x version which is risky at this stage.
                                        hence we are finding an alternative way.

                                        Any possibility of calling garbage collection periodically?
                                        Will this accumulated memory get freed with garbage collection?

                                        JonBJ Axel SpoerlA 2 Replies Last reply
                                        0
                                        • A AdarshKale

                                          There are a few deprecated APIs used and many syntax changes if we upgrade to the latest 6.x version which is risky at this stage.
                                          hence we are finding an alternative way.

                                          Any possibility of calling garbage collection periodically?
                                          Will this accumulated memory get freed with garbage collection?

                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by
                                          #20

                                          @AdarshKale said in Memory not released when multiple Image is loaded continuously:

                                          Any possibility of calling garbage collection periodically?
                                          Will this accumulated memory get freed with garbage collection?

                                          No. No.

                                          If you read referenced QTBUG you would see how involved the code is, and that it has been integrated into Qt6.x.

                                          1 Reply Last reply
                                          1

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved