Re: Freeing a linked list of Widgets
- From: Owen Taylor <otaylor redhat com>
- To: GTK MAILING LIST <gtk-list redhat com>
- Subject: Re: Freeing a linked list of Widgets
- Date: 07 Apr 1999 11:15:49 -0400
Gert <gs2@nowmoo.demon.nl> writes:
> On Tue, 6 Apr 1999, Ted Milker wrote:
>
> > Hey all, I'm trying to figure out the best way to free a linked list of
> > widgets. Could someone give me a small snippet of code to do this? I don't
> > even know which *free() function to use. :(
> >
> > Thanks,
> > Ted
>
> Try this (assiming you have a GList of those widgets):
> /****/
> void free_widget_list(GList *list) {
> GList *l;
> for(l = list; l != NULL; l = l->next)
> gtk_widget_destroy(l->data);
> g_list_free(list);
> }
> /****/
Or, slightly more compactly (though one funccall slower)
g_list_foreach (list, (GFunc)gtk_widget_destroy, NULL);
g_list_free (list);
BUT...
This is only appropriate if you have a list of _toplevel_
widgets. Most of the time, child widgets (that is, widgets
that have been added to a parent) will automatically
be freed as appropriate.
If they are non-toplevel widgets without a parent, then there
are some additional refcounting complications to deal
with.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]