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. Valgrind: possible memory-leak when setting up connections
Forum Updated to NodeBB v4.3 + New Features

Valgrind: possible memory-leak when setting up connections

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 2.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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by Christian Ehrlicher
    #2

    @unzu said in Valgrind: possible memory-leak when setting up connections:

    StateDevice.cpp:31

    So what's at this line?

    I think you can't fix it and it's Qt internal. As long as it's only 1 block it's not really a leak which should worry you.

    /edit: you leak DataDevice

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    U 1 Reply Last reply
    4
    • Christian EhrlicherC Christian Ehrlicher

      @unzu said in Valgrind: possible memory-leak when setting up connections:

      StateDevice.cpp:31

      So what's at this line?

      I think you can't fix it and it's Qt internal. As long as it's only 1 block it's not really a leak which should worry you.

      /edit: you leak DataDevice

      U Offline
      U Offline
      unzu
      wrote on last edited by
      #3

      @Christian-Ehrlicher
      Oh! Thats definitely a leak, i forgot to pass the parent object to the QObject in the initializer-list.
      Fixed that, thanks. Should now be on github, too.
      The leaks are still detected, though :(
      So you think I should just go with it?
      I've spend already multiple days looking for a solution and hints on the internet, guess i really have to move on - it's just that those tiny details drive me nuts.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @unzu said in Valgrind: possible memory-leak when setting up connections:

        So you think I should just go with it?

        yes, as long as it's only 1 block - so the 'leak' only occurs one time it's fine. It can e.g. an initialization of a Qt internal memory block which is needed for connections and is never deallocated since it's needed until the very end of the program.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        U 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          @unzu said in Valgrind: possible memory-leak when setting up connections:

          So you think I should just go with it?

          yes, as long as it's only 1 block - so the 'leak' only occurs one time it's fine. It can e.g. an initialization of a Qt internal memory block which is needed for connections and is never deallocated since it's needed until the very end of the program.

          U Offline
          U Offline
          unzu
          wrote on last edited by
          #5

          @Christian-Ehrlicher The thing is, I intended to call this 'driver' multiple times, maybe even many thousand times in the lifetime of the program.
          Like 48 times a day per device, multiple devices, and the program is running in endless mode.

          Do you know if there is way to see the total memory consumption of a program? So that I can create and delete the statemachine like 10000 times and see if the memory size is rising?

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            So when you call it multiple times and only one block leaks my explanation is correct, or? It's a one-and-only allocation.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • U Offline
              U Offline
              unzu
              wrote on last edited by unzu
              #7

              I don't think so, maybe I'm getting this wrong, but everytime I create a new instance of my statemachine it creates those connections inside which maybe cause leaking?

              Christian EhrlicherC 1 Reply Last reply
              0
              • U unzu

                I don't think so, maybe I'm getting this wrong, but everytime I create a new instance of my statemachine it creates those connections inside which maybe cause leaking?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @unzu said in Valgrind: possible memory-leak when setting up connections:

                which maybe cause leaking?

                Again: valgrind only shows "160 bytes in 1 blocks" - no matter how often you call it, so how do you think it will leak every time you call it?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • U Offline
                  U Offline
                  unzu
                  wrote on last edited by
                  #9

                  Sorry, I probably don't understand what's really happening here. I thought that whenever I create an instance of the statemachine there is some memory allocated which is not freed on deletion of the statemachine, so that for every instance there is some lost memory until I stop the application or run out of memory.

                  Again, I'm no expert and just trying to build a small application that won't crash after x hours of usage..

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @unzu said in Valgrind: possible memory-leak when setting up connections:

                    I thought that whenever I create an instance of the statemachine there is some memory allocated which is not freed on deletion of the statemachine, so that for every instance there is some lost memory until I stop the application or run out of memory.

                    Then you would see more than one of such valgrind warning or more than one block allocation, or?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • U Offline
                      U Offline
                      unzu
                      wrote on last edited by
                      #11

                      Ah I see - so if a leak would happen everytime I create a new instance of the object, the number of blocks would increase?

                      I compiled the project with Visual Studio because you can see the process-memory easily there.
                      After fixing another leak I found in one of the subclasses of the statemachine-class the process memory stayed steadily on ~13MB, even after creating and deleting more than 100.000 instances of the statemachine.

                      So i think (if there is really a leak) that it is, as you have suggest, once in the lifetime of the program.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @unzu said in Valgrind: possible memory-leak when setting up connections:

                        I create a new instance of the object, the number of blocks would increase?

                        correct, therefore I suspect it's some static memory internally needed for the signal/slot handling and can be ignored. You just have to start worring about a 'leak' when it increases with the times you call a function. If it stays at a specific (small) amount it's fine. Esp. when the amount is 1 :)

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        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