Re: Releasing client-side pixmaps



Dag Helstad wrote:

Hi, I'm trying to minimize the memory usage of a GTK application which uses
a GtkPixmap to show a background pixmap.
The X server keeps a server-side copy of the pixmap, but it seems a
client-side copy is kept in my application.

X pixmaps unlike the X images are always (except the MIT-SHM shared pixmaps)
stored on the Xserver side. The copy you mean is only small structure (GdkPixmap)
gdk uses to represent the X pixmap.


Here is the code fragment which creates a gtk_pixmap from my bitmap (which
is stored in PNG format):

/****************************/
GtkWidget* LoadImage(const std::string& location)
{
  GtkWidget* widget = NULL;
  GdkPixbuf* image = NULL;
  GdkPixmap* pixmap = NULL;
  GdkBitmap* mask = NULL;

  image=gdk_pixbuf_new_from_file(location.c_str());

image's ref count == 1


  gdk_pixbuf_render_pixmap_and_mask(image, &pixmap, &mask, 100);

pixmap's and mask's ref counts == 1



  widget = gtk_pixmap_new(pixmap, mask);

GtkPixmap adds its own references to pixmap and mask, so
pixmap's and mask's ref counts == 2



  gdk_pixmap_unref(pixmap);

pixmap's ref count == 1, so its still alive


  gdk_bitmap_unref(mask);

mask's ref count == 1, so its still alive


  gdk_pixbuf_unref(image);

image's ref count reaches 0 - it freed.


return widget;
}
/****************************/

I unref() the GdkPixbuf, GdkPixmap and GdkBitmap. Does the GtkPixmap widget
keep a client-side copy of the pixmap? Can I free the client-side pixmap
without destroying my GtkPixmap widget?

The GtkPixmap widget (deprecated in gtk+-2.0, by the way) doesnt create a copy
of the GdkPixmap and GdkBitmap it increases thier ref counts instead.

Olexiy





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]