Hi, On Sun, 2004-11-21 at 15:33 -0500, Jeramy Rutley wrote:
Thanks for that. I now have another memory-related question. I'm just wondering how to safely remove things out of a GSList without having a memory leak. I didn't find the documentation explicit. So I have a block of code that looks like this: GSList *gslist;
/* here's where my question actually begins */ gslist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fileRequ)); while(gslist) { printf("%s\n",(char *)gslist->data); g_free(gslist->data); list = g_slist_remove(gslist, gslist->data); } g_slist_free(gslist); gtk_widget_destroy(fileRequ);
(Note that the condition on your while-loop guarantees that when g_slist_free(gslist) is run, the gslist will be empty, so that the call to g_slist_free is a no-op.)
What I want to do is remove an element off of the front of the GSList, use it, and then free it. In the code above, does the g_slist_remove free the list element, or do I need to do a g_free on each individual element? According to the gtk_file_chooser_get_filenames documentation, it says that the g_free is required for each element. In that case, there's the g_free followed by a g_slist_remove... does it care that it's pointing to an already freed element?
g_slist_remove will free the list node (the GSlist structure), but it will not free the data field. So you do need to call g_free(gslist->data).
Also, in the documentation, it says that gtk_clist_* is deprecated. Does anyone know the GTK 2.4 equivalent of it?
The modern way to do lists and trees in gtk in using GtkTreeView/GtkTreeStore/GteListStore and friends. The gtk tutorial at <http://www.gtk.org/tutorial/> has some information about them, and Tim-Philipp Müller has a whole tutorial on them at <http://scentric.net/tutorial/treeview-tutorial.html> HTH, -- m -- Mariano Suárez-Alvarez <msuarezalvarez arnet com ar> http://www.gnome.org/~mariano
Attachment:
signature.asc
Description: This is a digitally signed message part