Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:46:32+00:00 2026-06-09T17:46:32+00:00

I have an issue with the following code: #include <QtGui/QImage> int main(int argc, char*

  • 0

I have an issue with the following code:

#include <QtGui/QImage>

int main(int argc, char* argv[]) {
  QImage qimage(100, 100, QImage::Format_ARGB32);
  qimage.fill(Qt::white);
  qimage.save("test.png", "PNG", 70);

  return 0;
}

to be compiled as followed:

gcc -I/usr/include/qt4 test.cpp -lQtGui

The code generates a proper image. However, when I valgrind it:

valgrind --leak-check=full ./a.out

it yields a series of lost blocks, like the following one:

==5974== 158 (56 direct, 102 indirect) bytes in 1 blocks are definitely lost in loss record 54 of 79
==5974==    at 0x402B9B4: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==5974==    by 0x4E4E427: QLibraryPrivate::findOrCreate(QString const&, QString const&) (qlibrary.cpp:437)
==5974==    by 0x4E4E721: QLibrary::setFileNameAndVersion(QString const&, QString const&) (qlibrary.cpp:1110)
==5974==    by 0x56290DF: ???

or this one :

==5974== 396 (56 direct, 340 indirect) bytes in 1 blocks are definitely lost in loss record 61 of 79
==5974==    at 0x402B9B4: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==5974==    by 0x4E4E427: QLibraryPrivate::findOrCreate(QString const&, QString const&) (qlibrary.cpp:437)
==5974==    by 0x4E44FB6: QFactoryLoader::updateDir(QString const&, QSettings&) (qfactoryloader.cpp:145)
==5974==    by 0x56F9E67: ???

I spare you the full log, you can just execute the same at home 🙂

I tried to understand and they seems to lie in the following lines I found in the source code for QImageWriter:

QFactoryLoader *l = loader();
QStringList keys = l->keys();

It seems to me that when you first try to generate a PNG image, it builds something that will be reused each time you will build a PNG image and that memory is never freed.
The destructor for QFactoryLoader seems to know how to clean things, and I would love to personally do a delete l; but there is no way to call it since QFactoryLoader is private to the implementation of Qt.

One could argue that this is not a real memory leak since there would be only one key per image format, but imho, the clean way to do things would be to be able to clear everything before quitting.

So my question: is there any way to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:46:33+00:00Added an answer on June 9, 2026 at 5:46 pm

    Qt’s image I/O functionality is based around plugins. When you request a QImage to a load a png file the PNG library is loaded as a QObject once, it is not unloaded until the program exits – this is what Valgrind sees as a memory leak.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem compiling the following code: #include <stdio.h> #include <limits.h> int main
I have the following code: #include <openssl/bn.h> #include <openssl/rsa.h> unsigned char* key; RSA* rsa
I have an issue with using the following code in my CakePHP app. In
I'm having an issue with rails involving javascript. Basically, I have the following code:
I have got the following issue, my function appends code to a string $string
I have a problem with the following code: #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <iostream>
I have used the following code to create two threads: //header files #include <pthread.h>
I have the following code (include-guards omitted for simplicity's sake): = foo.hpp = struct
I have the following code: #include <iostream> #include <string> #include <iomanip> #include <locale> #include
I have the following code #include <iostream> #include <cstddef> #include <string> #include <memory> class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.