Re: freeing gslist data ?



On Sun, 2003-06-22 at 17:04, Mohammed Sameer wrote:
Hi,
suppose that i have a GSList *foo and a gchar *bar
and i've used something like this:
foo = g_slist_append(foo, g_strdup(bar));
now when i free the list, Do i have to manually iterate over the list 
and free the ->data ?
i've browsed the code but i didn't understand well the gallocator things

Yes, you do need to free the data yourself. For a list of strings,
g_slist_foreach (list, (GForeachFunc) g_free, NULL); should do it.

The GAllocator stuff is just the way GLib handles lists & such. It
allocates a bunch of them, and when you do g_(s)list_free, it puts them
back in the pool for other code to use (so it doesn't actually free the
list, it just marks the list items for re-use).

-- 
Peace,

    Jim Cape
    http://ignore-your.tv

    "It is literally true that, like Christianity, Socialism
     has conquered the world by defeating itself."
        -- Alexander Berkman, ABC of Anarchism

Attachment: signature.asc
Description: This is a digitally signed message part



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