Re: [Vala] The behaviour of G.List and other containers.



Hi Alexandre,

On Tue, 2007-09-18 at 22:38 -0300, Alexandre Moreira wrote:
What is the correct way to deal with the assisted memory management
and Containers, such as the G.List ? I noticed that whenever I add
something to the list, it gets automatically ref()ed, but it seems I
can't get it to automatically unref() it. Is this the intended
behaviour ? Am I doing something stupid ? Or is it just that I am
supposed to rely on automatic ref()ing and then unref() by myself
(this last option I believe is a bit odd, though) ?

The intended behavior is that Vala should take care of ref() and unref()
when adding an object to resp. removing an object from a GList or other
container. GList doesn't support calling unref/free functions on removal
by itself as for example GHashTable, so valac needs some workarounds to
accomplish correct memory management.

Those workarounds are still lacking at the moment, so it's relatively
easy to get memory leaks when working with a GList. The simple case of
adding objects to an empty list and then automatically calling unref()
for each object when the list is destroyed should work fine, though.

Please post a test case where memory management doesn't work as it
should and we'll try to fix it as soon as possible.

I didn't quite test, but I suppose the same behaviour is replicated
across the other glib containers, as they all share the same style of
API.

It works fine with GHashTable as long as you pass the right callbacks to
the full constructor.

Regards,

Jürg




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