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:
@
void VisualizzazioneWidget::immagineArrivata(bool esito)
{
pixmap.loadFromData(http.readAll());
if(pixmapItem==NULL)
{
pixmapItem=scene.addPixmap(pixmap);
}
else
{
pixmapItem->setPixmap(pixmap);
}
}
@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:
@
void VisualizzazioneWidget::immagineArrivata(bool esito)
{
image.loadFromData(http.readAll());
if(pixmapItem==NULL)
{
pixmapItem=scene.addPixmap(QPixmap().fromImage(image));
}
else
{
pixmapItem->setPixmap(QPixmap().fromImage(image));
}
}
@
I also replaced all other occurrence of QPixmap with QImage in other part of the application.I seen this in QT documentation:
@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? -
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.
-
[quote author="Luca" date="1276064407"]but I don't know if I must free X server memory in a different way.[/quote]
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.
-
I found this link that talk about X server and memory leak:
http://www.rahul.net/kenton/txa/feb96.htmlThere is a part where it says:
@
Who Frees the Memory and How?Now that you've determined when dynamic memory is allocated by the X libraries, the next questions should be:
- does the application have to free the memory?
- if yes, when can it safely free the memory?
- what function should be used to free the memory?
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.
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.
@ -
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:
@
QImageReader is a specialized class which gives you more control when reading images. For example,
you can read an image into a specific size by calling setScaledSize(), and you can select a clip rect,
effectively loading only parts of an image, by calling setClipRect(). Depending on the underlying support
in the image format, this can save memory and speed up loading of images
@