Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt's QTextEdit has big memory leak problem
Qt 6.12 LTS is out! See what's new in the release blog

Qt's QTextEdit has big memory leak problem

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 7 Posters 4.7k Views 2 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.
  • JonBJ JonB

    @cyberpunker
    Well, it makes sense to me that disabling the undo buffer should save a lot of memory in the case of what your code does. But you say not.

    You cannot assume that memory consumed by a C++/Qt program will be returned to the operating system on freeing variables. It would not be unexpected that this memory is returned to the pool of available memory to be reused by your program, but not deallocated from your program back to the OS. That's not how memory deallocation typically works.

    What you should test is:

    1. Press button to call setdata() once.
    2. Press button to call cleardata() once. Preferably have that actually delete and recreate textEdit so that we have a clear slate.
    3. Look at process's memory consumption.
    4. Now repeat step #1 a second time.
    5. Now repeat step #2 a second time.
    6. Now look at memory consumption again. Is it twice the amount which was used when measured at step #3? Hopefully (but not guaranteed) it will not be twice the amount, because the memory allocated during step #4 will have a chance to re-use the memory allocated in step #1 which was freed in step #2?
    cyberpunkerC Offline
    cyberpunkerC Offline
    cyberpunker
    wrote on last edited by cyberpunker
    #10

    @JonB

    I change the QTextEdit to QPlainTextEdit .

    My test :
    bootup : 56MB ( it is too big I think , just so little a demo )

    setdata : 279 MB
    cleardata: 180MB ( does not release all )

    setdata : 279 MB
    cleardata: 180MB

    setdata : 279 MB
    setdata : 459 MB
    cleardata: 262MB ( does not release all )

    If it can release cleanly , I would appreciate it .

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @JonB said in Qt's QTextEdit has big memory leak problem:

      Look at process's memory consumption.

      With a proper tool like e.g. valgrind or heaptrack, not with top nor Task Manager!

      cyberpunkerC Offline
      cyberpunkerC Offline
      cyberpunker
      wrote on last edited by cyberpunker
      #11

      @Christian-Ehrlicher

      I compile and run the Application.exe of Qt's example which is a simple text edit, repeat paste text into it , make the memory consumption roket up , then delete them all , the phenomenon recurrs.

      aha_1980A 1 Reply Last reply
      0
      • cyberpunkerC cyberpunker

        @Christian-Ehrlicher

        I compile and run the Application.exe of Qt's example which is a simple text edit, repeat paste text into it , make the memory consumption roket up , then delete them all , the phenomenon recurrs.

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #12

        @cyberpunker And how do you measure?

        Qt has to stay free or it will die.

        cyberpunkerC 1 Reply Last reply
        0
        • aha_1980A aha_1980

          @cyberpunker And how do you measure?

          cyberpunkerC Offline
          cyberpunkerC Offline
          cyberpunker
          wrote on last edited by
          #13

          @aha_1980

          Xfce's task manager

          aha_1980A 1 Reply Last reply
          0
          • cyberpunkerC cyberpunker

            @aha_1980

            Xfce's task manager

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #14

            @cyberpunker

            quoting @Christian-Ehrlicher:

            With a proper tool like e.g. valgrind or heaptrack, not with top nor Task Manager!

            Regards

            Qt has to stay free or it will die.

            cyberpunkerC 1 Reply Last reply
            0
            • aha_1980A aha_1980

              @cyberpunker

              quoting @Christian-Ehrlicher:

              With a proper tool like e.g. valgrind or heaptrack, not with top nor Task Manager!

              Regards

              cyberpunkerC Offline
              cyberpunkerC Offline
              cyberpunker
              wrote on last edited by
              #15

              @aha_1980

              any problem with xfce's task manager ?

              I run valgrind in qtcreator, it can't endup ,so I give up.

              aha_1980A 1 Reply Last reply
              0
              • cyberpunkerC cyberpunker

                @aha_1980

                any problem with xfce's task manager ?

                I run valgrind in qtcreator, it can't endup ,so I give up.

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #16

                @cyberpunker said in Qt's QTextEdit has big memory leak problem:

                any problem with xfce's task manager ?

                The OS does not display all freed memory instantly. Only if new memory requirements appear, the freed memory is taken into account.

                So what you see in task manager is only updated if required.

                Qt has to stay free or it will die.

                1 Reply Last reply
                4
                • cyberpunkerC cyberpunker

                  @JonB

                  I change the QTextEdit to QPlainTextEdit .

                  My test :
                  bootup : 56MB ( it is too big I think , just so little a demo )

                  setdata : 279 MB
                  cleardata: 180MB ( does not release all )

                  setdata : 279 MB
                  cleardata: 180MB

                  setdata : 279 MB
                  setdata : 459 MB
                  cleardata: 262MB ( does not release all )

                  If it can release cleanly , I would appreciate it .

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #17

                  @cyberpunker said in Qt's QTextEdit has big memory leak problem:

                  setdata : 279 MB
                  cleardata: 180MB ( does not release all )
                  setdata : 279 MB
                  cleardata: 180MB

                  This part at least confirms my suggestion that your program will be able to re-use memory which gets freed, does it not?

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

                    Hi,

                    Since it's a log and you likely are going to scroll through it, you might want to consider using a QListView and have one row per line of your log.

                    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
                    2
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #19

                      Hi
                      When using TextEdit as log viewer , its often a good idea to
                      use
                      setUndoRedoEnabled(false);
                      so it doesn't keep a copy around to be able to undo text changes.

                      Oh. sorry. already mentioned.

                      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
                      • Unsolved