GtkImage/GdkPixbuf memory management



Could someone clarify something that doesn't seem to be explicit in the
API documentation?

Consider the following code:

static GtkWidget *image; /* initialized to a fixed GtkImage */
 
void update(const char *s)
{
  GdkPixbuf *pixbuf;
  
  pixbuf=gdk_pixbuf_new_from_file(s, NULL);
  if(pixbuf) {
    gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);  /* <---| */
    g_object_unref(G_OBJECT(pixbuf));  
  } else
    gtk_image_clear(GTK_IMAGE(image));
}

The question is: have I done enough to prevent a memory leak?

Suppose I call this function twice in succession:
update("file1"); update("file2");
When the indicated line executes the second time, is GtkImage smart
enough to realize that it's replacing an existing image got from a
GdkPixbuf, that when it _set_from_pixbuf that image it added a reference
to the pixbuf, and that it should therefore now unref the pixbuf before
replacing the image?

Thanks!




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