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 leak width QPainter/QPrinter
Forum Updated to NodeBB v4.3 + New Features

memory leak width QPainter/QPrinter

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpainterqprintermemory leak
18 Posts 8 Posters 3.6k Views 4 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.
  • L labrass

    @JonB Yes you're right. So I do that with Qimage instead of QPixmap as suggested @KroMignon but it's the same thinks, the memory go further up after reprinting.

    KroMignonK Offline
    KroMignonK Offline
    KroMignon
    wrote on last edited by
    #9

    @labrass said in memory leak width QPainter/QPrinter:

    but it's the same thinks, the memory go further up after reprinting.

    The only reason I see is that paint.end() does not work, and do not release memory.

    On what kind of printer do you send the image?
    Is the printer accessible/working?

    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

    L 1 Reply Last reply
    0
    • L labrass

      @JonB Yes you're right. So I do that with Qimage instead of QPixmap as suggested @KroMignon but it's the same thinks, the memory go further up after reprinting.

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

      @labrass said in memory leak width QPainter/QPrinter:

      Yes you're right.

      In what way? I asked whether memory still increases further if you show the same pictures again, or whether it does not increase any more than it already did?

      1 Reply Last reply
      0
      • KroMignonK KroMignon

        @labrass said in memory leak width QPainter/QPrinter:

        but it's the same thinks, the memory go further up after reprinting.

        The only reason I see is that paint.end() does not work, and do not release memory.

        On what kind of printer do you send the image?
        Is the printer accessible/working?

        L Offline
        L Offline
        labrass
        wrote on last edited by labrass
        #11

        @KroMignon I tried with "microsoft print to pdf printer" and with photo printer (citizen cy printer) plugged by usb, these result are the same, the print task work but still increase memory without down back.

        @JonB I mean, I did as you asked above, and the memory still increases after reprinting the sames pictures second time.

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #12

          I did see memory leak of QPixmap(Qt 5.9.5) before through valgrind on Ubuntu. It was a small issue for me and ignored. But I can not reproduce it from my code now. Make a debug qt build and debug into it to see what is going on if it is a big issue for you.

          L 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            I did see memory leak of QPixmap(Qt 5.9.5) before through valgrind on Ubuntu. It was a small issue for me and ignored. But I can not reproduce it from my code now. Make a debug qt build and debug into it to see what is going on if it is a big issue for you.

            L Offline
            L Offline
            labrass
            wrote on last edited by
            #13

            @JoeCFD Ok, unfortunately, I not very at ease for rebuild Qt...
            but I can show the output in debug runtime I notice some strange error, maybe related to this issue (sorry for some french word):

            Exception levée à 0x00007FF88998D759 (KernelBase.dll) dans testPainter.exe : WinRT originate error - 0x80040155 : 'Échec de la recherche de l’inscription de proxy pour IID : {2047E320-F2A9-11CE-AE65-08002B2E1262}.'.
            onecore\com\combase\dcomrem\marshal.cxx(1284)\combase.dll!00007FF88A82DF9B: (caller: 00007FF88A82D354) ReturnHr(7) tid(21cc) 80040155 Interface non enregistrée
                Msg:[Failed to marshal with IID={2047E320-F2A9-11CE-AE65-08002B2E1262}] 
            onecore\com\combase\dcomrem\marshal.cxx(1179)\combase.dll!00007FF88A82D384: (caller: 00007FF88A82973B) LogHr(7) tid(21cc) 80040155 Interface non enregistrée
            onecore\com\combase\dcomrem\marshal.cxx(1119)\combase.dll!00007FF88A9311E0: (caller: 00007FF88A82904D) ReturnHr(8) tid(21cc) 80040155 Interface non enregistrée
            Exception levée à 0x00007FF88998D759 (KernelBase.dll) dans testPainter.exe : 0x80040155: Interface non enregistrée.
            Exception levée à 0x00007FF88998D759 (KernelBase.dll) dans testPainter.exe : 0x80040155: Interface non enregistrée.
            1 Reply Last reply
            0
            • A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #14

              How do you measure memory usage?
              Which metric do you use?
              Can you repeat until the process crashes because it is out of memory?

              The reason I ask: Depending on which metric you look at, memory may not look to be freed because the OS decides it's not needed, and the process can keep it for the time being. Once other processes request more memory, it should be freed up.
              However, if you can crash your process because it runs out of memory, that would be an indication of a true memory leak.

              It hasn't gotten any easier in the past 20 years to analyze memory leaks...

              L 1 Reply Last reply
              1
              • A Asperamanca

                How do you measure memory usage?
                Which metric do you use?
                Can you repeat until the process crashes because it is out of memory?

                The reason I ask: Depending on which metric you look at, memory may not look to be freed because the OS decides it's not needed, and the process can keep it for the time being. Once other processes request more memory, it should be freed up.
                However, if you can crash your process because it runs out of memory, that would be an indication of a true memory leak.

                It hasn't gotten any easier in the past 20 years to analyze memory leaks...

                L Offline
                L Offline
                labrass
                wrote on last edited by
                #15

                @Asperamanca After several print task in debug mode, I have many "out of memory" error in debug output and my computer even started to have black screen.

                Capture d’écran 2021-04-01 112048.png

                1 Reply Last reply
                0
                • AaronCA Offline
                  AaronCA Offline
                  AaronC
                  wrote on last edited by
                  #16

                  I can reproduce this on Windows using either an HP LaserJet printer or Microsoft Print to PDF printer. This has been happening in my application for awhile (maybe a year or more) but I always thought it was a leak in my code. After debugging I found that the Qt printing system is most likely at fault, and probably only on Windows. (I build my code for both Mac OS X and Windows and the Mac OS X doesn't leak memory.)

                  The following bug report has been filed:

                  https://bugreports.qt.io/browse/QTBUG-92272

                  It contains a couple sample projects that reproduce this memory leak. The project QPainterTest.zip attached to that bug report contains the following leaky code :

                  void Widget::showEvent(QShowEvent *)
                  {
                      QPrinter printer;
                  
                      // select the printer
                      QSharedPointer<QPrintDialog> printDialog(new QPrintDialog(&printer, Q_NULLPTR));
                      if (printDialog->exec() != QDialog::Accepted)
                      {
                          return;
                      }
                  
                      printer.setPageSize(QPageSize(QPageSize::Letter));
                      printer.setResolution(300);
                      printer.setFullPage(true);
                  
                      QPainter painter;
                      if (!painter.begin(&printer))
                      {
                          return;
                      }
                  
                      for (int i=0; i<10; i++)
                      {
                          if (i != 0)
                          {
                              printer.newPage();
                          }
                  
                          QImage image(300*8.5, 300*11, QImage::Format_ARGB32);
                          image.fill(qRgb(215, 215, 215));
                          painter.drawImage(0, 0, image);
                      }
                  }
                  

                  Any thoughts would be much appreciated.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #17

                    @AaronC said in memory leak width QPainter/QPrinter:

                    Any thoughts would be much appreciated.

                    The problem is inside QWin32PrintEngine::drawPixmap() where hbitmap is not released once it is used via SelectObject() for unknown reason. All looks fine according the docs and intensive searching.

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

                    AaronCA 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      @AaronC said in memory leak width QPainter/QPrinter:

                      Any thoughts would be much appreciated.

                      The problem is inside QWin32PrintEngine::drawPixmap() where hbitmap is not released once it is used via SelectObject() for unknown reason. All looks fine according the docs and intensive searching.

                      AaronCA Offline
                      AaronCA Offline
                      AaronC
                      wrote on last edited by
                      #18

                      @Christian-Ehrlicher Thanks for tracking that down. Hope Qt gets it fixed soon.

                      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