Re: gtk_combo_set_popdown_strings() coppies data?



On Thu, 18 Jan 2001, Marco Quezada wrote:

<...>
Clearing the GList is very simple, the GList is a pointer to the list of strings so
all you have to do is set the pointer to NULL and your GList will be empty, for
example:

if your GList is declared as something like this:

GList *variables_list_items;

Then in your code where you decide to clear the contents of the GList do the
following:

variables_list_items = NULL;

Won't this leak memory?  I think the proper way to do it is to iterate
through the GList, freeing all the strings if necessary, and then call
g_list_free() on the list like so:

GList *listptr

...

if((listptr = variables_list_items)) {
  while(listptr) {
    if(listptr->data)
      g_free(listptr->data);
    listptr = g_list_next(listptr);
  }

  g_list_free(variables_list_items);
}

or am I missing the point...

Having read the source for the combo box, it uses a GtkList for the
popdown window, and when you set the contents using
gtk_combo_set_popdown_strings, it does not keep a pointer to the GList
(or any of it's data pointers) you pass it, it creates new labels in
the GtkList for all the strings, so it should be perfectly safe to free
them and the GList when you are done.

Hope this helps

Jonathan










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