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. Qt Application Slowing Down
Forum Update on Monday, May 27th 2025

Qt Application Slowing Down

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 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.
  • J Offline
    J Offline
    jastmc
    wrote on last edited by
    #1

    I'm developing a Qt application for the Beaglebone.

    I have a few different screens and as I move forward and back through the different screens, the application gets slower and slower. In the end it gets very slow.

    When one screen is finished, I move to the next with code like the following:-
    @ Startup *j = new Startup();
    j->showMaximized();
    this->close();
    @

    Here is a link to the output of htop. https://www.dropbox.com/s/gcl23i3p12zkt8s/Htop_Output.jpg

    New instances of my application _mita6 _ seem to be created when I navigate between screens. How can I prevent or delete these?

    Am I doing something wrong when navigating between screens or should I be somehow deleting the old screen when I move to the next one? The application is snappy enough in the first couple of screens. How can I free up the processor/memory to make the application more responsive?

    Any help is appreciated.

    Regards,
    James

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

      Hi,

      If you create a new screen each time you go back and forth without deleting any of them then you have a memory leak. Either create each screen once and reuse them (better) or delete them once you're done with one.

      You might be interested in the QWizard design for your application

      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
      • J Offline
        J Offline
        jastmc
        wrote on last edited by
        #3

        OK, I looked at QWizard but the fastest way to sort this would be to delete each screen when I'm done with it.

        I've spent the day searching the forums and trying things like:-
        @this->close();
        delete ui;
        @

        This is executed as last thing before exit and the memory leak is still there.

        What am I missing?

        James

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goblincoding
          wrote on last edited by
          #4

          As SGaist said, in C++, everything that gets created must be destroyed. In other words, for every "new", there must be a "delete" so if you allocate memory, you are responsible for its release.

          OR

          You can also make use of Qt's parent/child object ownership model where parents delete their children when they themselves are deleted

          OR

          if you are using QWidgets, have a look at the Qt::WA_DeleteOnClose flag

          OR

          Any combination of the above.

          If you are unfamiliar with memory management in C++, I suggest you start reading up on that :)

          Oh, and I suggest you look into keeping your screens in tact (i.e. creating once for the duration of your application's lifetime) also as per SGaist's suggestion. As a rule, dynamic memory allocation off the heap is much slower than static allocation off the stack.

          Good luck!

          http://www.goblincoding.com

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

            To add to goblincoding, delete ui doesn't delete your widget.

            Reading this again made me think of another thing: you seem to be creating each new screen from your soon to be deleted screen. You should rather have a manager that handles that for you.

            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
            • N Offline
              N Offline
              nunu
              wrote on last edited by
              #6

              Hi,

              You have to rearrange your application in line with some of the above posts.

              I think each time you run the code you posted above, you are creating new instances of "Startup" with your "j" variable pointing to the newest instance, and the previous one getting lost.

              You can also use something like:
              ...
              Startup j;
              j.show()
              ...
              and arrange it so that j goes out of scope (so that it is destroyed automatically) when you are done with the window. You will need some code to manage the different windows in this manner.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jastmc
                wrote on last edited by
                #7

                I replaced the above code with the following in every location I create a new screen.
                @ Startup *j = new Startup();
                j->showMaximized();
                j->setAttribute(Qt::WA_DeleteOnClose);
                this->close();
                @

                This seems to reduce the memory consumed as shown in Htop but the application is still slowing down. Is this the correct way to do this?

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

                  As said before, recreating constantly each screen is not the best way to do it.

                  Has for the slowdown, without knowing what your program does that's pretty much crystal ball debugging. Do you initialize anything ? Do you have some code that might timeout etc...

                  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
                  • N Offline
                    N Offline
                    nunu
                    wrote on last edited by
                    #9

                    I an not an expert but just thinking logically, over writing the "j" variable each time points it to the new instance of "Startup". I don't think either Qt or the Compiler will have any reference to the old instance (in this case the current window) and hence no way to free the memory used by it. I would try to find another more straight forward way to do this.

                    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