Widget memory allocation



I recently noticed that my gnome applications were leaking
memory. I tried to find the holes, but I couldn't find any. Now
I am not sure whether I have understood how memory is managed in 
GTK (and gnome). Is memory for widgets automatically freed with
the parent? When should widgets be freed/destroyed (and how)?

Here's an example that leaks about 8KB of memory every time I open
and close the dialog. Should the dialog be freed? Is it me, gnome
or something else that is leaking. I am using:
* glib 1.2.6
* gtk+ 1.2.6
* gnome-libs 1.0.54

Regards,
Björn Andersson
 
-- snip --
#include <gnome.h>
static gint
delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
        gtk_main_quit();
        return FALSE;
}

void
clicked_cb(GtkButton *button,
	   gpointer user_data)
{
	GtkWidget *dialog;

	dialog = gnome_dialog_new("The title",
				  GNOME_STOCK_BUTTON_OK,
				  GNOME_STOCK_BUTTON_CANCEL,
				  NULL);
	gnome_dialog_run_and_close(GNOME_DIALOG(dialog));
}

int
main(int argc, char *argv[])
{
	GtkWidget *app;
	GtkWidget *button;

	gnome_init("memtest", "0.1", argc, argv);
	
	app = gnome_app_new("memtest", "My Wonderful App");
	gtk_signal_connect(GTK_OBJECT(app), "delete-event",
			   GTK_SIGNAL_FUNC(delete_event),
			   NULL);

	button = gtk_button_new_with_label("Click Me");
	gtk_signal_connect(GTK_OBJECT(button), "clicked",
			   GTK_SIGNAL_FUNC(clicked_cb),
			   NULL);

	gnome_app_set_contents(GNOME_APP(app), button);
	gtk_widget_show_all(app);
	gtk_main();
	return 0;
}
-- snip --

-- 
Björn Andersson  <bjorn@lifix.fi>                        +358-50-3412556
Lifix Systems Oy <http://www.lifix.fi/>     Professional Linux Solutions
Tekniikantie 21, FIN-02150 Espoo                          +358-9-4375272



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