Re: [Vala] GLib.SList as a property

2009/7/5 Lucas Hermann Negri <kkndrox gmail com>:

I have a property of GLib.SList type, defined this way:

public SList<string> labels { get{return h_labels;} set{h_labels = value;} }

But this leaks memory. What's the correct way of doing this?

I'd generally avoid using GLib's List classes in Vala. They don't
handle the reference and Vala can't cope with it automatically, so
"owned" generic argument will always leak.

You have three possibilities:

1.) Use SList<unowned string> -  that will mean the strings will have
to be stored somewhere else, too
2.) Use SList<string*> and manage the memory yourself, just like you
(perhaps) are used to in C
3.) Use Gee.List - I believe there is already a linked list
implementation, which hasn't yet been committed to the master git,

Also, how do I create a property of type string[]? I tried this way:

public string[] test { get; set; }

But the generated C code doesn't compiles.

That's a bug. Please check whether it was already reported, and if
not, report it with some minimal test case.

Another issue:

I'm using a PangoLayout created using
Pango.cairo_create_layout(, but I need to call unref() by hand
in the destructor. This is the correct behavior or just a bug in the
binding (other objects are managed automatically) ?

Everything that requires you to manage memory or referencing manually
(aside from pointers) is a bug. In this case, to fix it you just need
to remove the "unowned" modifier in the bindings.

Thanks for the attention.

You're welcome :)

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