Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why qThreadpool do not clear its queue
QtWS25 Last Chance

Why qThreadpool do not clear its queue

Scheduled Pinned Locked Moved Unsolved General and Desktop
memory leakqthreadpoolmemory managmen
10 Posts 6 Posters 3.3k 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.
  • E Offline
    E Offline
    Ehsun
    wrote on last edited by Ehsun
    #1

    I have wrote the following code by using qthreadpool. The problem is that qt does not free the memory after finishing the application. My codes are attached bellow (noting change even I uncomment the commented parts). Could you please help me?
    Main
    Header file
    Implementation

    jsulmJ 1 Reply Last reply
    0
    • E Ehsun

      I have wrote the following code by using qthreadpool. The problem is that qt does not free the memory after finishing the application. My codes are attached bellow (noting change even I uncomment the commented parts). Could you please help me?
      Main
      Header file
      Implementation

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ehsun Why do you allocate myThread on the heap? Allocate it on the stack. You also should delete all myRunnable instances you created when they are not needed anymore.
      P.S.: it is easier to post the source code directly here instead of photograph your display and post links to the pictures.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        http://www.cplusplus.com/doc/tutorial/dynamic/

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          To add to my fellow, QThreadPool deletes the runners by default however, with your disabled destructor, all the int arrays you allocated won't get cleaned. Either use a two dimensional vector or properly clean your myList content.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • E Offline
            E Offline
            Ehsun
            wrote on last edited by
            #5

            @SGaist I have checked the code with destructor enabled but the memory leak still exist.

            J.HilkJ 1 Reply Last reply
            0
            • E Ehsun

              @SGaist I have checked the code with destructor enabled but the memory leak still exist.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Ehsun what destructor exactly?
              You allocate memory in Main as well as in Implementation without freeing it later/on program exit.

              only Header file is free of leakage.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                Ehsun
                wrote on last edited by
                #7

                @J-Hilk you can uncomment the comented part in the destructor of myRunnable class or uncomment the for loop in run() method but after that nothing will change and no memory will free at the end

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Just one thing, when an application quits, the memory it used is freed. What the OS does with this newly freed memory is by no mean related to Qt and varies from one platform to another.

                  So what exactly are you observing and how ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  JonBJ 1 Reply Last reply
                  2
                  • SGaistS SGaist

                    Just one thing, when an application quits, the memory it used is freed. What the OS does with this newly freed memory is by no mean related to Qt and varies from one platform to another.

                    So what exactly are you observing and how ?

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

                    @SGaist
                    Well under Windoze & Linux all memory is certainly freed on executable exit, so for Qt I can only imagine MacOS could work differently. So as you say the OP needs to explain what behaviour he is observing, and that the Qt app really has terminated.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Like I already wrote, it has nothing to do with Qt. Qt is a C++ framework, it doesn't do anything special with respect to memory management.

                      So yes, since the OP wrote that the memory was not freed after the application ended then he needs to elaborate on that.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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