High memory usage when using multiple QPixmap
-
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);
-
How large (dimensions) are your pixmaps?
-
@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
-
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.
-
@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.
-
@Narutoblaze said in High memory usage when using multiple QPixmap:
Is this normal ?
Yes because QPixmap (and other Qt classes) are implicitly shared.
-
@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.
-
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.
-
"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);
-
Hi,
See if this provides some explanation (read the comments as well):