Hello,
I need to remove all and clear GList in my gtk+ application. How can i do this?
Thank you
Hello,
I need to remove all and clear GList in my gtk+ application. How can i do this?
Thank you
You have to use the API to free the list and update the container containing the List in your UI application appropriately.
void g_list_free (GList *list);
This way the memory allocated for creating the list is freed and the UI container is refreshed to display a blank list.
The function g_list_free can do the job, but don't forget to free the data before if allocated dynamically, as also said here: in that case you have to go through each element of the list and use g_free (if allocated with g_malloc), or free (if allocated with malloc), or whatever matches the alloc function (e.g delete for new in C++ ...)
An easy way to free the list and the data in it, and then clear the list, goes like this:
g_list_foreach(list, g_free, NULL);
g_list_free(list);
list = NULL;
NULL
is the empty list, so that last line clears it so that you can use it again.
Of course if your data should be freed by some other function, use that function instead of g_free()
as ShinTakezou remarks.