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. How to minimize memory usage in runtime
QtWS25 Last Chance

How to minimize memory usage in runtime

Scheduled Pinned Locked Moved General and Desktop
17 Posts 6 Posters 16.8k 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.
  • M Offline
    M Offline
    Morris
    wrote on last edited by
    #1

    How can I reduce the memory usage when I minimize my app to tray?
    I have call hide() on my main window, but the memory usage doesn't drop down.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      It can't use less memory only because you've minimized it. The whole program is still running as before, you've just hidden the window.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackfacewa
        wrote on last edited by
        #3

        The reason as Volker mentioned.
        I think that you should do something after minimized your app.
        1> Try to free all the objects what have you created and not used after minimized your app;
        2> Try to free the memory which not used after minimized your app.

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

          But keep in mind that you must recreate the destroyed objects (not necessarily QObjects!) as soon as you show the window again. And if the objects are important to your application, you will have to save their state in one way or the other, which might be expensive or time consuming too. Also, it's annoying for the user, if he has to wait too long for the application to be restored on the screen in case you have to "wake" it up.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Morris
            wrote on last edited by
            #5

            But most of the time deleting something won't return all the memory to the OS(Windows).
            For example, I create a dialog which needs 14M. I can release 5M after delete it. I know that the 9M will be used again if I create something. But shouldn't the 9M memory return to OS when I minimize my app?

            Another problem I found is qt apps are consuming more and more memory... I'm working on Windows7. First is my app, at start-up, it takes 22M. After some time, it will grow to 50M, even if I don't "new" anything.
            Then I found QtCreator is sort of like that. At first it takes 106M, than after amount of time, it grows to 203M. Although if I close the project, I can get back 30M. The point is the total memory usage is climbing up. I'm really frustrated about this problem.

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              [quote author="Morris" date="1287935248"]Then I found QtCreator is sort of like that. At first it takes 106M, than after amount of time, it grows to 203M. Although if I close the project, I can get back 30M. The point is the total memory usage is climbing up. I'm really frustrated about this problem.[/quote]

              This memory will get freed later when required. I do not see much cause of concern here ... Does the usage continue to grow to say 300-400...eventually 700-800 MB or further? Then you might have a leak, which eventually will cause it to crash.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                It is up to the C runtime (on which C++ relies on most systems) to return memory back to the OS. If the heap is fragmented there might be not enough continuous memory at the end that can be freed and returned. So, depending on the application and library logic, it's likely that you do not have a classical memory leak in your code and your objects are destroyed, yet memory consumption is still increasing over time. There's hardly any solution to this problem, despite quitting and restarting the program.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on last edited by
                  #8

                  Morris: How do you measure the memory usage? Tools like the task manager in windows are not up to the task. Better use tools like valgrind (Linux, I do not know of a good tool for windows).

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #9

                    [quote author="Volker" date="1287937574"]There's hardly any solution to this problem, despite quitting and restarting the program.[/quote]

                    So, in the end, will the app crash in such a scenario or ... ?

                    1 Reply Last reply
                    0
                    • ? This user is from outside of this forum
                      ? This user is from outside of this forum
                      Guest
                      wrote on last edited by
                      #10

                      bq.
                      I do not know of a good tool for windows

                      I've used Rational Purify on win32. But I continue to seek out and ask others for more tools on windows ... :(

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        [quote author="chetankjain" date="1287937912"]So, in the end, will the app crash in such a scenario or ... ?[/quote]

                        Not necessarily. In such a scenario the increase of memory cunsumption is usually very slow, as the memory manager still has plenty of unused memory on the heap that can be reallocated. For further details one should use tools like valgrind, as Tobias mentioned. There's always a possibility of real memory leaks - even in the Qt libs themselves ;-)

                        If the memory consumption eventually stalls at a certain level, I'd leave it for that.

                        BTW: The memory allocation on Windows is a bit weird, as each DLL has it's own memory management, AFAIK. That adds even more complexity to this topic.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        1
                        • M Offline
                          M Offline
                          Morris
                          wrote on last edited by
                          #12

                          [quote author="Tobias Hunger" date="1287937783"]Morris: How do you measure the memory usage? Tools like the task manager in windows are not up to the task. Better use tools like valgrind (Linux, I do not know of a good tool for windows).[/quote]
                          I'm using process explorer(the data it provides is pretty the same as windows 7 task manager's). It's better than the one in WinXp. Though it won't tell me how much RAM exactly does my app consume, but it provides a clue. And the users won't be satisfied if they read the high memory usage from the task manager.

                          [quote author="chetankjain" date="1287937912"][quote author="Volker" date="1287937574"]There's hardly any solution to this problem, despite quitting and restarting the program.[/quote]

                          So, in the end, will the app crash in such a scenario or ... ?[/quote]
                          It's hard to make it crash this way, because you have so much memory. I'm not sure if is because heap fragmented. But at least I have check my code with Virtual Leak Detector, which tells me there's no leak(at least not in my code).

                          [quote author="chetankjain" date="1287938069"]bq.
                          I do not know of a good tool for windows

                          I've used Rational Purify on win32. But I continue to seek out and ask others for more tools on windows ... :([/quote]
                          I couldn't get Rational Purify to work. Is there any example?

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mr_gui
                            wrote on last edited by
                            #13

                            Same problem:

                            a simple mainwindow with a pushbutton. When I run the "not-doing-anything program" for several minutes the private and shared physical memory of the programm rises some kb's. My OS is WinXP and I didn't get a Rational Purify license yet,so I use the "ProcessExplorer" of Microsoft Sysinternals instead. I don't know how reliable this tool is, but I encountered that at programm startup the private memory is at a certain level. When I minimize the programm, the private memory drops to very low, when I maximize it again the private memory rises but to only half the size as it was at program startup.
                            Is this just the tool or what could it be?

                            I have to build an application that runs several months without stopping so even slowly rising memory usage of the program could be fatal.

                            Any suggestions?

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              tobias.hunger
                              wrote on last edited by
                              #14

                              mr_gui: Get yourself a good memory profiling tool.

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mr_gui
                                wrote on last edited by
                                #15

                                hunger: thank you, have you any suggestions?

                                I tried VMMap now, better overview over program's memory.
                                Memory behaviour by minimizing and get back to old sizeof the program stays the same.

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Morris
                                  wrote on last edited by
                                  #16

                                  Thanks for the info, mr_gui~

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    blex
                                    wrote on last edited by
                                    #17

                                    [quote author="mr_gui" date="1290688722"]I have to build an application that runs several months without stopping so even slowly rising memory usage of the program could be fatal.[/quote]

                                    I have experience with qt3-based graphics applications that run more than 6 months on Windows XP. The memory usage is increased nearly 5 times from original (10 - 50M) but system reacts quickly.

                                    If the application is running on Windows and uses custom dlls then look on utility rebase, it allows to specify the base address of the dll library. Specifying non-overlapping base address for all libraries significantly reduces physical memory usage. It is good optimization without code re-factoring :)

                                    Also think about splitting the tray-indicator and main application in 2 independent processes, if it is possible. And start main process when it is requested from the tray icon.


                                    Oleksiy Balabay

                                    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