Re: memprof and GTK/GNOME functions
- From: James Henstridge <james daa com au>
- To: Andy Kahn <ackahn netapp com>
- cc: Gnome List <gnome-list gnome org>
- Subject: Re: memprof and GTK/GNOME functions
- Date: Wed, 10 Nov 1999 09:59:05 +0800 (WST)
Here are some explanations of the problems you mention. Hopefully they
will clear it up for you. Unref'ing/freeing those structures was the
correct action.
On Tue, 9 Nov 1999, Andy Kahn wrote:
> Hi Owen,
>
> Just tried your MemProf utility and had some questions/comments. Upon
> using MemProf with my GTK/GNOME application, MemProf found two leaks
> in my code: one with gtk_style_new(), and one in my routine. I don't
> think gtk_style_new() is at fault, but here are the code snippets for
> both cases:
>
> [1]
> style = gtk_style_new(); /* MemProf points at this line */
> gtk_widget_set_style(GTK_WIDGET(d->data), style);
> gtk_widget_set_rc_style(GTK_WIDGET(d->data));
> gtk_widget_ensure_style(GTK_WIDGET(d->data));
gtk_style_new() returns a style object with reference count 1. Calling
gtk_widget_set_style() will increment the reference count on the style.
If you do not need the style object afterwards, call gtk_style_unref() on
it, so it can be cleaned up when the widget is destroyed.
>
> [2]
> GnomeUIInfo *menuitem;
>
> menuitem = g_new0(GnomeUIInfo, 2); /* MemProf points here */
> ... [ filling in fields for menuitem ] ...
> gnome_app_insert_menus_with_data(GNOME_APP(w->toplev),
> path, menuitem, data);
>
gnome_app_insert_menus_with_data() does not consume the menuitem
structure. If you do not need the GnomeUIInfo array afterwards, g_free()
it, or just use an array like:
GnomeUIInfo menuitem[2];
so that the C compiler will handle that for you.
I hope this helps,
James.
--
Email: james@daa.com.au
WWW: http://www.daa.com.au/~james/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]