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. Memory leaks and memory fragmentation
Forum Updated to NodeBB v4.3 + New Features

Memory leaks and memory fragmentation

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 1.5k 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.
  • B Offline
    B Offline
    BoLin
    wrote on 27 Jun 2023, 11:25 last edited by
    #1

    I am developing software and I find that the memory keeps going up, my program needs to use new and delete frequently, I suspect a memory leak or memory fragmentation. I checked with vld and found no reports of memory leaks, but memory was still slowly increasing. I couldn't tell if this was normal. I monitored memory by using the performance monitor that came with windows to monitor private bytes in process and by looking at committed memory in Task Manager Details. Is there any way but until this rise is normal? And are there any methods or tools to monitor and identify problems? My development and deployment environment is under windows, because the software needs to run for a long time, even memory fragmentation may have some impact, hope to get help, thank you very much

    J J C J 4 Replies Last reply 27 Jun 2023, 11:28
    0
    • B BoLin
      27 Jun 2023, 11:25

      I am developing software and I find that the memory keeps going up, my program needs to use new and delete frequently, I suspect a memory leak or memory fragmentation. I checked with vld and found no reports of memory leaks, but memory was still slowly increasing. I couldn't tell if this was normal. I monitored memory by using the performance monitor that came with windows to monitor private bytes in process and by looking at committed memory in Task Manager Details. Is there any way but until this rise is normal? And are there any methods or tools to monitor and identify problems? My development and deployment environment is under windows, because the software needs to run for a long time, even memory fragmentation may have some impact, hope to get help, thank you very much

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 27 Jun 2023, 11:28 last edited by
      #2

      @BoLin said in Memory leaks and memory fragmentation:

      performance monitor that came with windows

      This is not a proper tool for this.
      On Linux you would typically use Valgrind to look for memory leaks, not sure about Windows.

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

      1 Reply Last reply
      1
      • B BoLin
        27 Jun 2023, 11:25

        I am developing software and I find that the memory keeps going up, my program needs to use new and delete frequently, I suspect a memory leak or memory fragmentation. I checked with vld and found no reports of memory leaks, but memory was still slowly increasing. I couldn't tell if this was normal. I monitored memory by using the performance monitor that came with windows to monitor private bytes in process and by looking at committed memory in Task Manager Details. Is there any way but until this rise is normal? And are there any methods or tools to monitor and identify problems? My development and deployment environment is under windows, because the software needs to run for a long time, even memory fragmentation may have some impact, hope to get help, thank you very much

        J Offline
        J Offline
        JonB
        wrote on 27 Jun 2023, 11:32 last edited by
        #3

        @BoLin said in Memory leaks and memory fragmentation:

        even memory fragmentation may have some impact

        As @jsulm says for the overall picture. We often have people coming saying "Qt leaks", turns out it does not. Just saying.

        But I just wanted to say: it's one thing to look for and resolve if there are any memory leaks. But if you expect a C++ program to not cause "memory fragmentation", at least potentially, good luck, I don't think that will be easy to affect....

        1 Reply Last reply
        0
        • B BoLin
          27 Jun 2023, 11:25

          I am developing software and I find that the memory keeps going up, my program needs to use new and delete frequently, I suspect a memory leak or memory fragmentation. I checked with vld and found no reports of memory leaks, but memory was still slowly increasing. I couldn't tell if this was normal. I monitored memory by using the performance monitor that came with windows to monitor private bytes in process and by looking at committed memory in Task Manager Details. Is there any way but until this rise is normal? And are there any methods or tools to monitor and identify problems? My development and deployment environment is under windows, because the software needs to run for a long time, even memory fragmentation may have some impact, hope to get help, thank you very much

          C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 27 Jun 2023, 11:52 last edited by
          #4

          @BoLin Check out MTuner. It's a great memory profiling and leak detection tool. It can help you diagnose all sorts of memory related issues. Apart from memory leak detection, varoius stats and graphing memory use over time it can point you to allocations with full callstack.

          B 1 Reply Last reply 28 Jun 2023, 11:01
          2
          • B BoLin
            27 Jun 2023, 11:25

            I am developing software and I find that the memory keeps going up, my program needs to use new and delete frequently, I suspect a memory leak or memory fragmentation. I checked with vld and found no reports of memory leaks, but memory was still slowly increasing. I couldn't tell if this was normal. I monitored memory by using the performance monitor that came with windows to monitor private bytes in process and by looking at committed memory in Task Manager Details. Is there any way but until this rise is normal? And are there any methods or tools to monitor and identify problems? My development and deployment environment is under windows, because the software needs to run for a long time, even memory fragmentation may have some impact, hope to get help, thank you very much

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 27 Jun 2023, 12:08 last edited by
            #5

            @BoLin about what quantities are we actually talking about here ?

            my program needs to use new and delete frequently

            how frequently ? the OS is "smart" and as such it gets annoyed quite fast. If you constantly request and free memory it is going to say "Fine keep it! I'll check later when you have made up your mind."


            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.

            B 1 Reply Last reply 28 Jun 2023, 11:11
            0
            • C Chris Kawa
              27 Jun 2023, 11:52

              @BoLin Check out MTuner. It's a great memory profiling and leak detection tool. It can help you diagnose all sorts of memory related issues. Apart from memory leak detection, varoius stats and graphing memory use over time it can point you to allocations with full callstack.

              B Offline
              B Offline
              BoLin
              wrote on 28 Jun 2023, 11:01 last edited by
              #6

              @Chris-Kawa I took a look at the software today, but the specific usage is still not clear. Have you ever used this software to detect memory fragmentation? If so, is it convenient to tell what program is being used? Because I did test this, I was using a single thread to continuously new and delete2 bytes, but that seems hard to test. And when the memory is really applied for, it is generally allocated 4k*n bytes, and I can hardly find the problem by simply observing the "commit memory" of the program.

              C 1 Reply Last reply 28 Jun 2023, 15:31
              0
              • J J.Hilk
                27 Jun 2023, 12:08

                @BoLin about what quantities are we actually talking about here ?

                my program needs to use new and delete frequently

                how frequently ? the OS is "smart" and as such it gets annoyed quite fast. If you constantly request and free memory it is going to say "Fine keep it! I'll check later when you have made up your mind."

                B Offline
                B Offline
                BoLin
                wrote on 28 Jun 2023, 11:11 last edited by
                #7

                @J-Hilk Hello! I'm so glad you could reply. My program currently new and delete about ten times per second, which is about two bytes of new space each time, and then free up. About 3 seconds will be a new large space, about new510241024 bytes. I don't know how to tell if there are memory leaks and memory fragmentation for long running programs. Thank you very much for your answer.

                1 Reply Last reply
                0
                • B BoLin
                  28 Jun 2023, 11:01

                  @Chris-Kawa I took a look at the software today, but the specific usage is still not clear. Have you ever used this software to detect memory fragmentation? If so, is it convenient to tell what program is being used? Because I did test this, I was using a single thread to continuously new and delete2 bytes, but that seems hard to test. And when the memory is really applied for, it is generally allocated 4k*n bytes, and I can hardly find the problem by simply observing the "commit memory" of the program.

                  C Offline
                  C Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on 28 Jun 2023, 15:31 last edited by Chris Kawa
                  #8

                  @BoLin said in Memory leaks and memory fragmentation:

                  Because I did test this, I was using a single thread to continuously new and delete2 bytes, but that seems hard to test

                  That's a pointless test. As you observed Windows allocates memory in pages, not bytes. Juggling 2 bytes in and out is basically nothing and will be in the same page all day long if you don't do any other allocations. The OS does not immediately page the memory out, so if you're reallocating the same small amount over and over the fragmentation does not increase significantly.
                  I haven't used MTuner for analyzing fragmentation, but I wouldn't be so sure it's the culprit.

                  As a side note - if you know you're allocating this same 2 bytes over and over and you're worried about it so much then wouldn't it make sense to stop doing that? Keep it around and overwrite, or use small preallocated pool for it if you have multiple of those.

                  B 1 Reply Last reply 29 Jun 2023, 00:14
                  3
                  • J JonB referenced this topic on 28 Jun 2023, 16:42
                  • C Chris Kawa
                    28 Jun 2023, 15:31

                    @BoLin said in Memory leaks and memory fragmentation:

                    Because I did test this, I was using a single thread to continuously new and delete2 bytes, but that seems hard to test

                    That's a pointless test. As you observed Windows allocates memory in pages, not bytes. Juggling 2 bytes in and out is basically nothing and will be in the same page all day long if you don't do any other allocations. The OS does not immediately page the memory out, so if you're reallocating the same small amount over and over the fragmentation does not increase significantly.
                    I haven't used MTuner for analyzing fragmentation, but I wouldn't be so sure it's the culprit.

                    As a side note - if you know you're allocating this same 2 bytes over and over and you're worried about it so much then wouldn't it make sense to stop doing that? Keep it around and overwrite, or use small preallocated pool for it if you have multiple of those.

                    B Offline
                    B Offline
                    BoLin
                    wrote on 29 Jun 2023, 00:14 last edited by
                    #9

                    @Chris-Kawa Is there an effective method for troubleshooting and monitoring memory fragmentation and memory leaks under Windows? How can I judge whether the current status is normal? I hope to receive your guidance

                    1 Reply Last reply
                    0

                    1/9

                    27 Jun 2023, 11:25

                    • Login

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