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.
  • NarutoblazeN Offline
    NarutoblazeN Offline
    Narutoblaze
    wrote on 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);
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • NarutoblazeN Narutoblaze

      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);
      
      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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

      NarutoblazeN 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        How large (dimensions) are your pixmaps?

        NarutoblazeN Offline
        NarutoblazeN Offline
        Narutoblaze
        wrote on 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

        Christian EhrlicherC 1 Reply Last reply
        0
        • NarutoblazeN Narutoblaze

          @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

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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

          NarutoblazeN 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            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.

            NarutoblazeN Offline
            NarutoblazeN Offline
            Narutoblaze
            wrote on 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.

            Christian EhrlicherC 1 Reply Last reply
            0
            • NarutoblazeN Narutoblaze

              @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.

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 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

              NarutoblazeN 1 Reply Last reply
              2
              • Christian EhrlicherC Christian Ehrlicher

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

                Is this normal ?

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

                NarutoblazeN Offline
                NarutoblazeN Offline
                Narutoblaze
                wrote on 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 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.

                  NarutoblazeN 1 Reply Last reply
                  0
                  • S SimonSchroeder

                    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.

                    NarutoblazeN Offline
                    NarutoblazeN Offline
                    Narutoblaze
                    wrote on 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 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

                      • Login

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