Re: gtk_widget_create_pango_layout



Claudiu wrote:

Hello,

I am using gtk_widget_create_pango_layout to create a PangoLayout for using in gdk_draw_layout. I would like to know if the memory allocated by gtk_widget_create_pango_layout is automatically freed by GTK, or should I free it ?

You should free it with g_object_unref().

I use this in an expose event callback, where I also use gdk_gc_new and gdk_pixmap_new among other functions, I use g_object_unref at the end of the callback function to free the memory allocated by the functions I enumerated above.

Opps, are you sure that you *have* to allocate/free such resources on each expose event call ? You can use widget's default GC by pointer 'widget->style->*_gc' [1], pixmap can be created once when widget gets mapped or when widget size changes...
[1] http://developer.gnome.org/doc/API/2.0/gtk/GtkStyle.html#GtkStyle-struct

Is there a rule on what should be freed and what not ?

If you create object you should free it (remove your reference, actually). Its safe when some internal library code still uses it - this code holds its own reference and object will not be freed until reference counter > 0.

   Olexiy





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