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. QML Loader leaks memory
Qt 6.11 is out! See what's new in the release blog

QML Loader leaks memory

Scheduled Pinned Locked Moved QML and Qt Quick
28 Posts 11 Posters 29.5k Views 3 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.
  • C Offline
    C Offline
    chiragbprajapati
    wrote on last edited by
    #3

    Hi Michael,

    I am using 35 different qml files and at a time only one or no one would be in loader. when i load the new qml file it increase the memory but strangly it is not releasing when i remove it from the loader.even after load-unload-load same file will also increase the memory but the different is, it occupies lesser memory than first time occupied. I am using qt 4.7.3 but i also checked with 4.7.4 and got same result.

    if engine is not clearing the cache then how can i clear it?

    Regards,
    CPra

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #4

      Hi,

      Do you mean that on unload no memory is released, or or that only some of the memory is released? I would expect the latter to be the case, with the component cache growing each time a completely new qml file is loaded (and this growth should at worst be bounded by the number of unique qml files that need to be loaded).

      You could try using QDeclarativeEngine::clearComponentCache() to see if that makes any difference in your case. There is also a manual gc() function you can call from JS to force garbage collection, though I wouldn't expect it to make a difference in this case.

      Regards,
      Michael

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chiragbprajapati
        wrote on last edited by
        #5

        Hi,

        Yes exactly, Loader is not releasing memory when i specify source as null. but if now i assign new qml file (other than before assigned) it will allot memory from previously unfreed memory if possible. you can check by simply making Loader element which simply loads two different file which just contains lots of rectangles.

        Regards,
        CPra

        1 Reply Last reply
        0
        • A Offline
          A Offline
          altera_2011
          wrote on last edited by
          #6

          Have you been able to resolve this? I'm running into this exact same thing.

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

            How serious is that memory leak ?

            1 Reply Last reply
            0
            • N Offline
              N Offline
              njeisecke
              wrote on last edited by
              #8

              I've made similar observations. I suspect it's memory fragmentation.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                altera_2011
                wrote on last edited by
                #9

                Our leak is very serious, on a fully loaded QML (images and stuff) it leaks about 1MB per load. Which is really bad considering we have about 128MB total memory on the Windows CE device we use. We have to reboot the Windows CE device way to often. (several times a day, TPHB is not really happy about that, nor am I).

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  chiragbprajapati
                  wrote on last edited by
                  #10

                  Hi altera,

                  I havent sort out this problem but rather to reduce start up delay leakage in my application i have loaded files only once and afterwards setting visible to true/false so finally i am not unloading file.

                  Regards,
                  CPra

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

                    Yes, that is what I tried as well but sadly due to the memory constraints that pushed us up right to the maximum. Which caused more out of memory errors.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      aabc
                      wrote on last edited by
                      #12

                      Are you sure the memory leaks are not because you forgot to free memory you allocated on the heap ?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        altera_2011
                        wrote on last edited by
                        #13

                        No I'm 100% sure on top of that I've recreated the leak using 2 empty QMLs

                        https://bugreports.qt-project.org/browse/QTBUG-26032?focusedCommentId=179280#comment-179280

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          altera_2011
                          wrote on last edited by
                          #14

                          One thing that I did notice is that when I add

                          @m_View->engine()->clearComponentCache();@

                          The leak is 10 times worse!

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

                            This is all rather scary. Happens for me, too - due to big JPGs/PNGs loaded, it adds +40MB per unload.

                            (Z(:^

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              aabc
                              wrote on last edited by
                              #16

                              Does it happen only on Qt 4.7.4 or also on Qt 4.7.3 Qt 4.8 and Qt 5 ?

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

                                4.7.4 + 4.8.2 I have not tested 5 since we require Windows CE support.

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

                                  In my case:

                                  4.7.4, 4.8.1 - QtQuick 1.
                                  Qt5.0.0 - QtQuick 2.

                                  (Z(:^

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

                                    I also saw it on embedded linux.
                                    Its a very serious leak.
                                    It happens all the time there is a loading of new qml pages

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      aabc
                                      wrote on last edited by
                                      #20

                                      We found that the reason for the memory leak is Qt's function:

                                      QDeclarativeEngine::clearComponentCache()

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

                                        Please report a bug in the bug tracker then. Not many Qt Developers (those building Qt itself, not so much those using it) read these forums.

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          aabc
                                          wrote on last edited by
                                          #22

                                          Can you please send me a link ?

                                          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