Re: Memory Leak with pango_layout_new()



On Thursday 09 September 2004 20:31, martin dempsey wrote:
I've got a major memory leak in an applicaton and I tracked it down to the
following: if I create a PangoLayout with pango_layout_new() and then use
pango_layout_set_text(), I get a memory leak even when I try to free the
memory with g_object_unref(). However, if I replace those function calls
with a call to gtk_widget_create_pango_layout(), there is no memory leak.

Looks like you're leaking the PangoContext:

 void suspectDrawText(GdkDrawable *pixmap, GdkGC *gc, char *m_text)
 {
+  PangoContext *context;
   PangoLayout *layout;
   PangoFontDescription *fontdesc;
   PangoRectangle ink, logical;
        
 #ifdef LEAKS    
+   context = gdk_pango_context_get();
-   layout = pango_layout_new(gdk_pango_context_get());
+   layout = pango_layout_new(context);
+   g_object_unref (context);
   pango_layout_set_text(layout, m_text, -1);
 #else
   layout = gtk_widget_create_pango_layout(GTK_WIDGET(window),m_text);
 #endif
        
Cheers
 -Tim



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