On 12/30/2009 06:37 AM, hermann wrote: > >>>> Am Mittwoch, den 30.12.2009, 01:18 +1100 schrieb Patrick Shirkey: >>>> >>>> >>>>> Hi, >>>>> >>>>> I have some code in gtk2 that is leaking and I can't fix it. Over the >>>>> past two nights I have managed to get the leak down from 200MB/minute to >>>>> 200MB/10 minutes but I can't get rid of it completely. It's annoying >>>>> because it increments in 200MB blocks so I have to wait for up to 10 >>>>> mins to see if it is fixed or not. I have tried valgrind but it doesn't >>>>> really like jack and did not give me any useful output. I have traced >>>>> the leak through normal debugging and have verified that it does not >>>>> happen if I disable this offending code. >>>>> >>>>> This code is run in the widgets realize event and the event is triggered >>>>> every 500ms. >>>>> > And when you use style->font_desc, you could move the font discription > to init, and change only the text every 500ms. > > >
Thanks for your ideas on nailing this bug. Below is what I have come up with now thanks to your input. I am still seeing a leak after about 8 mins. The slightly annoying thing to me is that it increments in a block of 200MB and not gradually. It's as though pango/gtk is requesting an additional block of memory cache to fill up each time. The widget class is a custom class called gtkmeter.c which doesn't have an internal font description or text value. The code below is for writing the notch values onto the gtkmeter so this method is called multiple times for each redraw of the widget. There are 16 instances of the widget with 11 notch values on each one making a total of 176 requests to this method every 500ms. At 200MB/8 mins that is about 20kb leak per redraw or approx 120 bytes per request. db is a float value passed in the method variables. +++++++++++++++++++++++++++++++++++++++ PangoLayout *pl; PangoRectangle rect; GtkStyle *style = gtk_widget_get_style(widget); char text[3]; snprintf(text, 3, "%.0f", fabs(db)); pl = gtk_widget_create_pango_layout(widget,text); pango_layout_get_pixel_extents(pl, &rect, NULL); x = pos - rect.width/2 + 1; y = width/2 - rect.height / 2 + 1; if (x < 1) { x = 1; } else if (x + rect.width > length) { x = length - rect.width + 1; } gdk_draw_layout(widget->window, widget->style->black_gc, x, y, pl); last_label_rect->width = rect.width; last_label_rect->height = rect.height; last_label_rect->x = x; last_label_rect->y = y; g_object_unref (pl); +++++++++++++++++++++++++++++++++++++++ Patrick Shirkey Boost Hardware Ltd _______________________________________________ Linux-audio-dev mailing list Linux-audio-dev@lists.linuxaudio.org http://lists.linuxaudio.org/listinfo/linux-audio-dev