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. High memory usage when using multiple QPixmap

High memory usage when using multiple QPixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsviewpixmapmemory leakqgraphicsitemqgraphicsscene
10 Posts 4 Posters 1.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.
  • N Offline
    N Offline
    Narutoblaze
    wrote on 18 Jun 2023, 15:40 last edited by
    #1

    My application consume 15-18 mb of memory on average but when i try to use 3 QPixmap and add to scene my memory jumps to 78-84 mb but everything is good when i use only one QPixmap i am beginner and i have no idea what is causing this.

    Application is very large so i am providing little snippet of how i am using the QPixmap Don't hesitate to ask more if needed thanks

    Snippet of my code :

    auto Pix1 = QPixmap("c:/images/apple.png);
    auto Pix2 = QPixmap("c:/images/orange.png);
    auto Pix3 = QPixmap("c:/images/mango.png);
    
    scene->addPixmap(Pix1);
    scene->addPixmap(Pix2);
    scene->addPixmap(Pix3);
    
    C 1 Reply Last reply 18 Jun 2023, 15:44
    0
    • N Narutoblaze
      18 Jun 2023, 15:40

      My application consume 15-18 mb of memory on average but when i try to use 3 QPixmap and add to scene my memory jumps to 78-84 mb but everything is good when i use only one QPixmap i am beginner and i have no idea what is causing this.

      Application is very large so i am providing little snippet of how i am using the QPixmap Don't hesitate to ask more if needed thanks

      Snippet of my code :

      auto Pix1 = QPixmap("c:/images/apple.png);
      auto Pix2 = QPixmap("c:/images/orange.png);
      auto Pix3 = QPixmap("c:/images/mango.png);
      
      scene->addPixmap(Pix1);
      scene->addPixmap(Pix2);
      scene->addPixmap(Pix3);
      
      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 18 Jun 2023, 15:44 last edited by
      #2

      How large (dimensions) are your pixmaps?

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

      N 1 Reply Last reply 18 Jun 2023, 16:21
      0
      • C Christian Ehrlicher
        18 Jun 2023, 15:44

        How large (dimensions) are your pixmaps?

        N Offline
        N Offline
        Narutoblaze
        wrote on 18 Jun 2023, 16:21 last edited by Narutoblaze
        #3

        @Christian-Ehrlicher apple.png and orange.png is 1224×1224 pixels and mango.png is 512×512 pixels

        These image are small in size 117 kb and 74 kb only

        C 1 Reply Last reply 18 Jun 2023, 17:09
        0
        • N Narutoblaze
          18 Jun 2023, 16:21

          @Christian-Ehrlicher apple.png and orange.png is 1224×1224 pixels and mango.png is 512×512 pixels

          These image are small in size 117 kb and 74 kb only

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 18 Jun 2023, 17:09 last edited by
          #4

          1224 * 1224 * 4bytes = 5992704 bytes
          512 * 5125 * 4bytes = 1048576 bytes

          -> so your 3 images take 13MB in memory. When they're copied around then 80MB is fine from my pov.

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

          N 1 Reply Last reply 18 Jun 2023, 17:41
          1
          • C Christian Ehrlicher
            18 Jun 2023, 17:09

            1224 * 1224 * 4bytes = 5992704 bytes
            512 * 5125 * 4bytes = 1048576 bytes

            -> so your 3 images take 13MB in memory. When they're copied around then 80MB is fine from my pov.

            N Offline
            N Offline
            Narutoblaze
            wrote on 18 Jun 2023, 17:41 last edited by Narutoblaze
            #5

            @Christian-Ehrlicher After more closer inspection i found when i have one pixmap it only consume around 600 kb but when i have 3 it consume 68 mb is it normal even though i don't copy it around just declaring it and adding to the scene. I don't understand, but it consume only 4mb when I don't add to the scene just declar it.

            Like this :

            auto Pix1 = QPixmap("c:/images/apple.png);
            auto Pix2 = QPixmap("c:/images/orange.png);
            auto Pix3 = QPixmap("c:/images/mango.png);
            

            but If i add one Pixmap to scene even 10 times the memory only increase little over 1mb Like this :

            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            scene->addPixmap(Pix1);
            

            Is this normal ? Even if this is normal is there any i can reduce memory consumption as much as possible.

            C 1 Reply Last reply 18 Jun 2023, 17:45
            0
            • N Narutoblaze
              18 Jun 2023, 17:41

              @Christian-Ehrlicher After more closer inspection i found when i have one pixmap it only consume around 600 kb but when i have 3 it consume 68 mb is it normal even though i don't copy it around just declaring it and adding to the scene. I don't understand, but it consume only 4mb when I don't add to the scene just declar it.

              Like this :

              auto Pix1 = QPixmap("c:/images/apple.png);
              auto Pix2 = QPixmap("c:/images/orange.png);
              auto Pix3 = QPixmap("c:/images/mango.png);
              

              but If i add one Pixmap to scene even 10 times the memory only increase little over 1mb Like this :

              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              scene->addPixmap(Pix1);
              

              Is this normal ? Even if this is normal is there any i can reduce memory consumption as much as possible.

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 18 Jun 2023, 17:45 last edited by
              #6

              @Narutoblaze said in High memory usage when using multiple QPixmap:

              Is this normal ?

              Yes because QPixmap (and other Qt classes) are implicitly shared.

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

              N 1 Reply Last reply 18 Jun 2023, 18:22
              2
              • C Christian Ehrlicher
                18 Jun 2023, 17:45

                @Narutoblaze said in High memory usage when using multiple QPixmap:

                Is this normal ?

                Yes because QPixmap (and other Qt classes) are implicitly shared.

                N Offline
                N Offline
                Narutoblaze
                wrote on 18 Jun 2023, 18:22 last edited by
                #7

                @Christian-Ehrlicher @Christian-Ehrlicher Can you kindly provide me any doc that explains this behaviour because it happens when i add the pixmap to the scene but before it's normal what does scene do or how many copy does it do to take it to 4mb just declaring to 80mb after adding to scene thats huge difference.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SimonSchroeder
                  wrote on 19 Jun 2023, 07:09 last edited by
                  #8

                  What exactly are you using for your scene? How do you add the pixmaps to the scene? One quick guess is that mipmapping is used internally to make things faster.

                  N 1 Reply Last reply 19 Jun 2023, 09:14
                  0
                  • S SimonSchroeder
                    19 Jun 2023, 07:09

                    What exactly are you using for your scene? How do you add the pixmaps to the scene? One quick guess is that mipmapping is used internally to make things faster.

                    N Offline
                    N Offline
                    Narutoblaze
                    wrote on 19 Jun 2023, 09:14 last edited by Narutoblaze
                    #9

                    @SimonSchroeder

                    "What exactly are you using for your scene?"
                    I did not understand what you mean.

                    Like this :

                    scene = new QGraphicsScene(this);
                    QGraphicsView view(&scene);
                    
                    auto Pix1 = QPixmap("c:/images/apple.png");
                    auto Pix2 = QPixmap("c:/images/orange.png");
                    auto Pix3 = QPixmap("c:/images/mango.png");
                    
                    scene->addPixmap(Pix1);
                    scene->addPixmap(Pix2);
                    scene->addPixmap(Pix3);
                    
                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      CPPUIX
                      wrote on 19 Jun 2023, 12:03 last edited by
                      #10

                      Hi,

                      See if this provides some explanation (read the comments as well):

                      StackOverflow: Qt6 QLabel / QPixmap excessive memory usage

                      1 Reply Last reply
                      0

                      9/10

                      19 Jun 2023, 09:14

                      • Login

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