June 8, 2010

Luca Luca
Ant Farmer
636 posts

QPixmap VS QImage, X server problem

 

Hi all,
I’m developing an application (for LINUX) that show some images downloaded from the web. The application works fine but I found a strange behavior of the X server.
The part of code is:

  1. void VisualizzazioneWidget::immagineArrivata(bool esito)
  2. {
  3.     pixmap.loadFromData(http.readAll());
  4.     if(pixmapItem==NULL)
  5.     {
  6.         pixmapItem=scene.addPixmap(pixmap);
  7.     }
  8.     else
  9.     {        
  10.         pixmapItem->setPixmap(pixmap);
  11.     }
  12. }

This function is execute every second.
I’v seen that in a PC without a dedicated graphic card the X server process memory usage grow up endless. While in a PC with a dedicated graphic card it doesn’t append.
To solve the problem I repalced QPixmap with QImage and all works fine:

  1. void VisualizzazioneWidget::immagineArrivata(bool esito)
  2. {
  3.     image.loadFromData(http.readAll());
  4.     if(pixmapItem==NULL)
  5.     {
  6.         pixmapItem=scene.addPixmap(QPixmap().fromImage(image));
  7.     }
  8.     else
  9.     {        
  10.         pixmapItem->setPixmap(QPixmap().fromImage(image));
  11.     }
  12. }

I also replaced all other occurrence of QPixmap with QImage in other part of the application.

I seen this in QT documentation:

  1. Note also that QPixmap, unlike QImage, may be hardware dependent. On X11, Mac and Symbian, a QPixmap is stored on the server side while a QImage is stored on the client side (on Windows, these two classes have an equivalent internal representation, i.e. both QImage and QPixmap are stored on the client side and don't use any GDI resources).

but why there is no problem if I have a dedicated graphics card? Is it a bug?

5 replies

June 8, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

Maybe not Qt problem? Looks like it is problem in intel (or what integrated card do you use) driver for xorg . As for me I noticed some other non obvious float bugs (but for now they are look like fixed) in it.

June 9, 2010

Luca Luca
Ant Farmer
636 posts

As documentation said:
“QPixmap is stored on the server side”
but I don’t know if I must free X server memory in a different way.

June 9, 2010

Jorj Jorj
Lab Rat
102 posts
Luca wrote:
but I don't know if I must free X server memory in a different way.

It would seem unlikely as things work fine with a dedicated graphics card, plus freeing X Server memory doesn’t strike me as the Qt way of doing things!

I’m with Denis, seems to be a driver issue with linux.

June 9, 2010

Luca Luca
Ant Farmer
636 posts

I found this link that talk about X server and memory leak:
http://www.rahul.net/kenton/txa/feb96.html

There is a part where it says:

  1. Who Frees the Memory and How?
  2.  
  3. Now that you've determined when dynamic memory is allocated by the X libraries, the next questions should be:
  4.  
  5.   1. does the application have to free the memory?
  6.   2. if yes, when can it safely free the memory?
  7.   3. what function should be used to free the memory?
  8.  
  9. Unfortunately, the X and, especially, the Motif documentation is not always clear about which case applies to a particular programming interface. In this section, I'll discuss some general guidelines in these areas. Next month's column will cover specific programming interfaces in more specific detail.
  10.  
  11. Freeing dynamic memory that shouldn't be freed can lead to many problems in the X libraries, including corrupting memory in use by X, freeing memory twice, and writing to invalid memory. Freeing memory with the wrong function can cause it to be improperly freed, including not freeing all the allocated memory.

August 5, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

does QPixmap::ShareMode have anything to do with this. It says on x11, you have to explicitly delete the pixmap handle. how would one use it?

also, not related to leak, but I’ve found QImageReader to be more efficient in terms of memory footprint, you might cross check.. below from qt docs:

  1. QImageReader is a specialized class which gives you more control when reading images. For example,
  2. you can read an image into a specific size by calling setScaledSize(), and you can select a clip rect,
  3. effectively loading only parts of an image, by calling setClipRect(). Depending on the underlying support
  4. in the image format, this can save memory and speed up loading of images

 
  ‹‹ cross desktop      QAtomicInt ››

You must log in to post a reply. Not a member yet? Register here!