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. QOpenglWidget memory leak
QtWS25 Last Chance

QOpenglWidget memory leak

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 6 Posters 1.5k 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.
  • X Offline
    X Offline
    xingqun
    wrote on 19 Feb 2024, 10:48 last edited by
    #1

    "Just like the program I provided, using Qt 5.15.2, Visual Studio 2019 (2022), a 4K display, and Intel integrated graphics, after compiling and running, when you hover the mouse back and forth between the top two buttons, continuously and rapidly repeating this action, you can observe that the program's memory usage keeps increasing until it crashes."

    code is here https://github.com/huxingqun/problems/tree/main/Qt/TestOpenGLWidget

    J Q 2 Replies Last reply 19 Feb 2024, 11:59
    0
    • X xingqun
      19 Feb 2024, 10:48

      "Just like the program I provided, using Qt 5.15.2, Visual Studio 2019 (2022), a 4K display, and Intel integrated graphics, after compiling and running, when you hover the mouse back and forth between the top two buttons, continuously and rapidly repeating this action, you can observe that the program's memory usage keeps increasing until it crashes."

      code is here https://github.com/huxingqun/problems/tree/main/Qt/TestOpenGLWidget

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 19 Feb 2024, 11:59 last edited by
      #2

      @xingqun Not sure what you expect? That somebody analyses your code and tells you what the problem is? Did you do any analysis on your own already? There are tools to search for memory leaks.

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

      X 1 Reply Last reply 19 Feb 2024, 14:48
      0
      • J jsulm
        19 Feb 2024, 11:59

        @xingqun Not sure what you expect? That somebody analyses your code and tells you what the problem is? Did you do any analysis on your own already? There are tools to search for memory leaks.

        X Offline
        X Offline
        xingqun
        wrote on 19 Feb 2024, 14:48 last edited by
        #3

        @jsulm The code logic should be fine. I encountered this memory leak issue in another project, so I wrote this demo to validate it further. I found that there is also a memory leak in this demo. Currently, I've used Visual Studio's memory tool to analyze it, but haven't identified the problem. Therefore, I'd like to seek help on this matter.

        J 1 Reply Last reply 20 Feb 2024, 04:40
        0
        • X xingqun
          19 Feb 2024, 14:48

          @jsulm The code logic should be fine. I encountered this memory leak issue in another project, so I wrote this demo to validate it further. I found that there is also a memory leak in this demo. Currently, I've used Visual Studio's memory tool to analyze it, but haven't identified the problem. Therefore, I'd like to seek help on this matter.

          J Offline
          J Offline
          JoeCFD
          wrote on 20 Feb 2024, 04:40 last edited by JoeCFD
          #4

          @xingqun your qt code is simple. It is likely openGL related leak. Test your code on Linux with valgrind and you may be able to find something

          Especially in void NVOpenGLWidget::paintGL()

          X 1 Reply Last reply 24 Feb 2024, 03:00
          0
          • J JoeCFD
            20 Feb 2024, 04:40

            @xingqun your qt code is simple. It is likely openGL related leak. Test your code on Linux with valgrind and you may be able to find something

            Especially in void NVOpenGLWidget::paintGL()

            X Offline
            X Offline
            xingqun
            wrote on 24 Feb 2024, 03:00 last edited by
            #5

            @JoeCFD Have you encountered any memory issues when mixing QOpenGLWidget and QWidget? I've noticed memory leaks even when using the official Qt demo.

            C 1 Reply Last reply 24 Feb 2024, 07:25
            0
            • X xingqun
              24 Feb 2024, 03:00

              @JoeCFD Have you encountered any memory issues when mixing QOpenGLWidget and QWidget? I've noticed memory leaks even when using the official Qt demo.

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 24 Feb 2024, 07:25 last edited by
              #6

              @xingqun said in QOpenglWidget memory leak:

              I've noticed memory leaks even when using the official Qt demo.

              Please provide a minimal, compilable example to reproduce this leak.

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

              X 1 Reply Last reply 25 Feb 2024, 04:06
              0
              • X xingqun
                19 Feb 2024, 10:48

                "Just like the program I provided, using Qt 5.15.2, Visual Studio 2019 (2022), a 4K display, and Intel integrated graphics, after compiling and running, when you hover the mouse back and forth between the top two buttons, continuously and rapidly repeating this action, you can observe that the program's memory usage keeps increasing until it crashes."

                code is here https://github.com/huxingqun/problems/tree/main/Qt/TestOpenGLWidget

                Q Offline
                Q Offline
                Qt embedded developer
                wrote on 24 Feb 2024, 08:02 last edited by
                #7

                @xingqun HI I recommened you to use gdb. Becauase it helps to get where exactly crash happens. In one of the my project i have found the crash using it.

                1 Reply Last reply
                0
                • C Christian Ehrlicher
                  24 Feb 2024, 07:25

                  @xingqun said in QOpenglWidget memory leak:

                  I've noticed memory leaks even when using the official Qt demo.

                  Please provide a minimal, compilable example to reproduce this leak.

                  X Offline
                  X Offline
                  xingqun
                  wrote on 25 Feb 2024, 04:06 last edited by
                  #8

                  @Christian-Ehrlicher You can compile and run this project. I'm using Qt 5.15.2 + VS2019. Then, compile and run it in Qt Creator. After running, maximize the software, then continuously drag the graphic back and forth with the mouse to keep it refreshing constantly. This way, you can observe the memory continuously increasing in the Task Manager.example.jpg
                  无响应.jpg
                  内存.jpg

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SamiV123
                    wrote on 25 Feb 2024, 06:27 last edited by
                    #9

                    Not sure if the memory leak reported here was on the CPU side or GPU side but at least regarding GPU memory there are definitely bugs in the implementation and I've seen issues on X11, NV, Qt5.

                    This is what I found at the time.

                    https://forum.qt.io/topic/92179/xorg-vram-leak-because-of-qt-opengl-application/12
                    https://community.khronos.org/t/xorg-vram-leak-because-of-qt-opengl-application/76910/2
                    https://bugreports.qt.io/browse/QTBUG-69429

                    X 1 Reply Last reply 25 Feb 2024, 13:49
                    0
                    • S SamiV123
                      25 Feb 2024, 06:27

                      Not sure if the memory leak reported here was on the CPU side or GPU side but at least regarding GPU memory there are definitely bugs in the implementation and I've seen issues on X11, NV, Qt5.

                      This is what I found at the time.

                      https://forum.qt.io/topic/92179/xorg-vram-leak-because-of-qt-opengl-application/12
                      https://community.khronos.org/t/xorg-vram-leak-because-of-qt-opengl-application/76910/2
                      https://bugreports.qt.io/browse/QTBUG-69429

                      X Offline
                      X Offline
                      xingqun
                      wrote on 25 Feb 2024, 13:49 last edited by
                      #10

                      @SamiV123
                      Here are a few observations we made during debugging from our end:

                      The higher the screen resolution, the faster the memory leak occurs. This was the direct cause we identified for the issue. When our client's computer with a 4K resolution runs our application, it experiences a memory leak leading to a crash. Therefore, we reproduced the problem using a 4K resolution. Both our custom demo and the official Qt demo consistently exhibit this behavior.
                      We used Visual Studio's memory snapshot for analysis but didn't find any leaked stack traces.
                      On machines with NVIDIA dedicated graphics cards, setting the software mode to high performance, thereby ensuring it primarily uses the dedicated GPU for OpenGL rendering, prevents memory leaks.
                      On machines with Intel integrated graphics, memory accumulation and leaks occur.
                      I suspect this could be due to the integrated graphics struggling to handle the data, resulting in memory accumulation. However, this is just my speculation. Currently, this issue is quite challenging, and we haven't found a solution yet.

                      S J 2 Replies Last reply 25 Feb 2024, 13:59
                      0
                      • X xingqun
                        25 Feb 2024, 13:49

                        @SamiV123
                        Here are a few observations we made during debugging from our end:

                        The higher the screen resolution, the faster the memory leak occurs. This was the direct cause we identified for the issue. When our client's computer with a 4K resolution runs our application, it experiences a memory leak leading to a crash. Therefore, we reproduced the problem using a 4K resolution. Both our custom demo and the official Qt demo consistently exhibit this behavior.
                        We used Visual Studio's memory snapshot for analysis but didn't find any leaked stack traces.
                        On machines with NVIDIA dedicated graphics cards, setting the software mode to high performance, thereby ensuring it primarily uses the dedicated GPU for OpenGL rendering, prevents memory leaks.
                        On machines with Intel integrated graphics, memory accumulation and leaks occur.
                        I suspect this could be due to the integrated graphics struggling to handle the data, resulting in memory accumulation. However, this is just my speculation. Currently, this issue is quite challenging, and we haven't found a solution yet.

                        S Offline
                        S Offline
                        SamiV123
                        wrote on 25 Feb 2024, 13:59 last edited by
                        #11

                        @xingqun

                        so just to confirm its a GPU memory leak not system memory ?

                        1 Reply Last reply
                        0
                        • X xingqun
                          25 Feb 2024, 13:49

                          @SamiV123
                          Here are a few observations we made during debugging from our end:

                          The higher the screen resolution, the faster the memory leak occurs. This was the direct cause we identified for the issue. When our client's computer with a 4K resolution runs our application, it experiences a memory leak leading to a crash. Therefore, we reproduced the problem using a 4K resolution. Both our custom demo and the official Qt demo consistently exhibit this behavior.
                          We used Visual Studio's memory snapshot for analysis but didn't find any leaked stack traces.
                          On machines with NVIDIA dedicated graphics cards, setting the software mode to high performance, thereby ensuring it primarily uses the dedicated GPU for OpenGL rendering, prevents memory leaks.
                          On machines with Intel integrated graphics, memory accumulation and leaks occur.
                          I suspect this could be due to the integrated graphics struggling to handle the data, resulting in memory accumulation. However, this is just my speculation. Currently, this issue is quite challenging, and we haven't found a solution yet.

                          J Offline
                          J Offline
                          JoeCFD
                          wrote on 26 Feb 2024, 20:07 last edited by JoeCFD
                          #12

                          @xingqun I did quick test with valgrind

                          ==================5.15.2 on Ubuntu 22.04
                          ==556545== LEAK SUMMARY:
                          ==556545== definitely lost: 256 bytes in 1 blocks
                          ==556545== indirectly lost: 32 bytes in 1 blocks
                          ==556545== possibly lost: 0 bytes in 0 blocks
                          ==556545== still reachable: 613,875 bytes in 10,922 blocks
                          ==556545== suppressed: 0 bytes in 0 blocks
                          ==556545== Reachable blocks (those to which a pointer was found) are not shown.
                          ==556545== To see them, rerun with: --leak-check=full --show-leak-kinds=all
                          ==556545==
                          ==556545== For lists of detected and suppressed errors, rerun with: -s
                          ==556545== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

                          ==================6.6.2 on Ubuntu 22.04
                          ==557606== HEAP SUMMARY:
                          ==557606== in use at exit: 346,588 bytes in 3,812 blocks
                          ==557606== total heap usage: 232,769 allocs, 228,957 frees, 1,005,388,571 bytes allocated
                          ==557606==
                          ==557606== LEAK SUMMARY:
                          ==557606== definitely lost: 0 bytes in 0 blocks
                          ==557606== indirectly lost: 0 bytes in 0 blocks
                          ==557606== possibly lost: 0 bytes in 0 blocks
                          ==557606== still reachable: 344,572 bytes in 3,791 blocks
                          ==557606== suppressed: 0 bytes in 0 blocks
                          ==557606== Reachable blocks (those to which a pointer was found) are not shown.
                          ==557606== To see them, rerun with: --leak-check=full --show-leak-kinds=all
                          ==557606==
                          ==557606== For lists of detected and suppressed errors, rerun with: -s
                          ==557606== ERROR SUMMARY: 6 errors from 4 contexts (suppressed: 0 from 0)

                          You may try a higher version of Qt5 or switch to Qt6.

                          1 Reply Last reply
                          0

                          8/12

                          25 Feb 2024, 04:06

                          • Login

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