RE: gtk_combo_set_popdown_strings() coppies data?



I think you are right in that there might be a memory leak by just assigning
the pointer to NULL. However in your example I don't quite understand if
variables_list_items is already the GList you need to free why is there the
need to create the second GList listptr? 

Marco Quezada
Aerospace Engineer
NLX Corporation
mquezada nlxcorp com
(703) 234-2100 Ext. 1028

-----Original Message-----
From: Jonathan Irwin [SMTP:jmi25 cam ac uk]
Sent: Thursday, January 18, 2001 10:56 AM
To:   Marco Quezada
Cc:   GTK Application Development List
Subject:      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







_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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