Re: Clarification on when to unref pixbufs -GtkIconView



On Tue, 2010-05-18 at 07:49 -0700, Paul Stuart wrote:

>   .
>    newPixBuf    = gdk_pixbuf_new_from_file ("myImage.png", &err);
>    scaledPixBuf = gdk_pixbuf_scale_simple(newPixBuf, ICON_VIEW_W, ICON_VIEW_H, GDK_INTERP_BILINEAR);

As a side note, you can load and scale immediately by using
gdk_pixbuf_new_from_file_at_scale(). This will be more efficient for
some image types.

>     
>    if(NULL == err) { // no error
>         gtk_list_store_append (store, &iter);
>         gtk_list_store_set(store, &iter, COL_PIXBUF0, scaledPixBuf, -1);
>         g_object_unref(scaledPixBuf);
>         g_object_unref(newPixBuf);

Yours is a more generic question than whether you need to do it for
iconviews or not. It has to do with how to manipulate a GObject instance
in liststores/treemodels. In general, any time you set a GObject in a
model, this will own a reference. So, if you don't need your reference,
you can remove it.

On the other way around, when you retrieve a GObject from a model,
you'll own a reference that you need to remove when you are done with
the object.

Claudio




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