Re: really freeing the memory allocated by g_slist

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

 



You're right, I don't free the elements in the list before calling g_slist_free.

Thank you.


2010/10/7 Tadej BorovÅak <tadeboro@xxxxxxxxx>
Hi.

2010/10/7 MÃrcio Ricardo Pivello <pivello@xxxxxxxxx>:
> Hi all.
> I use a library called GTS for computational geometry tasks, and it is
> heavily based on GLib data structures. Specifically, in _many_ occasions it
> returns a GSList* containing vertices, edges and so on, which you use and
> then delete with g_slist_free( ). In my work, during a transient simulation
> this kind of operation occurs at least tens of millions of times. Since
> g_slist_free( ) does not actually deallocates the memory used by the list,
> my program always ends consuming all available memory during the simulation
> (8 GB, when it should use just 10% of that).

I don't think g_slist_free() is problematic here. My guess would be
that you're not freeing your data that is pointed to by list elements.
g_slist_free() will only free memory that is used by GSList structs,
data that is pointed to by data member of GSList structure needs to be
freed separately.

For example, take gtk_icon_view_get_selected_items() func. Usual usage is:

GSList *items = gtk_icon_view_get_selected_items (icon_view);

/* Do something here */

g_slist_foreach (items, (GFunc)gtk_tree_path_free, NULL);
g_slist_free (items);

The important line is g_slist_foreach() line, where actual data that
is pointed to by nodes is freed.

Tadej

--
Tadej BorovÅak
tadeboro.blogspot.com
tadeboro@xxxxxxxxx
tadej.borovsak@xxxxxxxxx



--
MÃrcio Ricardo Pivello
Universidade Federal de UberlÃndia
Faculdade de Engenharia MecÃnica
LaboratÃrio de MecÃnica dos Fluidos
+55 (34) 3239 4040 ramal 618
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux