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 Manage in QML
Forum Updated to NodeBB v4.3 + New Features

Memory Manage in QML

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 6 Posters 9.2k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    Landy
    wrote on last edited by
    #1

    Hi guys,

    is there any good solution to manage memory in QML?
    the problem i got is that:
    i have a ListView in QML, and it displays some images in it. i will change the image data dynamic, adding or removing.
    i found that, i can't manage memory which was used by images. when i remove images from model, the memory will not be released.
    unfortunely, the image data i managed is big. so, the memory cost is high.
    so, u guys have any good idea?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Using your own image provider would be the way to go, I think.
      Look for "image provider" in the documentation for an example.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Landy
        wrote on last edited by
        #3

        Hi Andre,

        i tried iamge provider as your suggestion.
        since the provider will return a instance for each request, i still can not manage the memory.
        for example, method "requestImage" will return a copy of QImage, the copy will be used by QML. i don't know how to release the copy of QImage when i wanna release it.
        but a good news is that, i can use cache property of "Image" to prevent loading same images.
        but even i use cache property, and i use same images, every time i clear my model and reload, the memory used by app increases.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SteveKing
          wrote on last edited by
          #4

          Hi Landy

          Have you tried called "gc()" from your QML code? This should force the garbage collection and will clean up your images.

          Steve

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deimos
            wrote on last edited by
            #5

            Hi SteveKing,

            please what is gc() ? I didn't find any docs

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              It's javaScript method for forcing garbage collector to run. I don't think it applies to QML as such, but might clean JS side.

              (Z(:^

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Landy
                wrote on last edited by
                #7

                hi guys,
                i tried to use gc() in my code, but it didn't work.
                it seems that the truth is as sierdzio said, it doesn't apply to QML. that's why it didn't work on releasing image memory.
                besides image memory leak, it seems that list model in QML also causes memory leak.
                the list model, i mean , it's my own list model, which is based on QAbstractListModel.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SteveKing
                  wrote on last edited by
                  #8

                  Strange, we used list models and images all over our application I don't see a memory leak. The usage will increase up to the size of the image cache (in our use case) but will then level off. I have left ours showing a new image every second for a day and the usage was stable.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    chriadam
                    wrote on last edited by
                    #9

                    Take a look at the "QtQuick2 performance documentation":http://doc-snapshot.qt-project.org/5.0/qtquick-performance.html for information about gc() etc. Also, some hooks to control the size of the default image cache, and purge it of currently unreferenced pixmaps, were added to QtQuick2 recently.

                    Cheers,
                    Chris.

                    1 Reply Last reply
                    0

                    • Login

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