Re: really freeing the memory allocated by g_slist
- From: Tadej Borovšak <tadeboro gmail com>
- To: Márcio Ricardo Pivello <pivello gmail com>
- Cc: gtk-list gnome org
- Subject: Re: really freeing the memory allocated by g_slist
- Date: Thu, 7 Oct 2010 23:38:26 +0200
Hi.
2010/10/7 Márcio Ricardo Pivello <pivello gmail com>:
> 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 gmail com
tadej borovsak gmail com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]