Gtk+ memory management

2011-04-11 Thread Andrey Maklakov
 Hello.
Can you help me and answer some questions about memory management in Gtk+?

Look at next function:

  1 void
  2 tbar_makemenu (gint button)
  3 {
  4   const gchar *sid;
  5   GList *list = NULL;
  6
  7   tbar_widget.menu[button] = gtk_menu_new ();
  8   if (button == SID)
  9   fdir_getext (filesdir, &list);

 15   g_list_foreach (list, (GFunc) &list_menu_additem, &button);
 16   g_list_free_full (list, &g_free);
 17   gtk_widget_show_all (tbar_widget.menu[button]);
 18   gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON
(tbar_widget.button[button]), tbar_widget.menu[button]);
 19 }

  My questions:
1) line 7 creates new GtkMenu, its child of GInitiallyUnowned, so
refcount = 1, but it is floating reference. True?
2) line 18 reference this menu with GtkMenuToolButton, so refcount =
1, and it is now not floating. True?
3) When I call this function 2nd time, and reference toolbutton with
new menu in line 18, what will happen? Old menu will get refcount = 0
and will be destroyed, or it is memory leak?
4) Will be destroyed menu items of old menu (which created in call of
g_list_foreach on line 15)?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GList empty after iteration?

2011-09-12 Thread Andrey Maklakov
Hello Craig,
  I think this is because after first loop, variable "events" is NULL,
and you cant get first element of GList from it:

g_list_next()  --- Returns : the next element, or NULL if there are no
more elements.

> Hi All,
>
> I am confused about GList. My application is parsing a file and creating
> midi data with it. I am using GList to store the midi data.  I have
> created a GtkListStore to view the parsed data (to insure I am parsing
> the data properly).  So, below I iterate through the GList and "copy"
> the data into a tree view.  But, I am shocked to see that after I
> iterate through the GList, I cannot iterate through the list again.  I
> have debugged the list after the iteration with g_list_length(events)
> which shows the list length at 0.  What is up with this?  The first
> while loop has data, the second while loop has not data. The code is
> below-->
>
>        GtkTreeIter tree_iter;
>        events = g_list_reverse(events);
>        events = g_list_first(events);
>        while(events)
>        {
>                gtk_list_store_append (list_store, &tree_iter);
>                struct midi_event *me = events->data;
>                gtk_list_store_set(list_store, &tree_iter,
>                                   0, me->time_stamp,
>                                   1, me->event_type,
>                                   2, me->message1,
>                                   3, me->message2,
>                                  -1);
>                events = g_list_next(events);
>        }
>        /// this is where the list appears to be empty
>        events = g_list_first(events);
>        while(events)
>        {
>                g_print("midi event \n");
>                events = g_list_next(events);
>        }
>
> Thanks for any help!
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list