GNOME Bugzilla – Bug 472904
Massive memory leak in property handling
Last modified: 2007-09-20 21:30:17 UTC
There is a massive memory leak in property handling: public interface SpellCheckSection : GLib.Object { public abstract string! text { get; construct; } public abstract int length { get; construct; } public abstract string! language { get; set; } } SpellCheckSection.text.get () is compiled to: char* gtk_spell_check_section_get_text (GtkSpellCheckSection* self) { char* value; g_object_get (G_OBJECT (self), "text", &value, NULL); return value; } So with each reading of that property new memory is allocated. Unfortunatly vala never releases the string returned by gtk_spell_check_section_get_text. Possible solutions for the problem: a) Directly invoke g_object_get and free the temp variable when leaving the calling function. Safe but slow. b) Call the virtual property accessor which looks correct, expect for the missing const modifier: static char* gtk_spell_check_default_section_real_get_text (GtkSpellCheckDefaultSection* self) { g_return_val_if_fail (GTK_IS_SPELL_CHECK_DEFAULT_SECTION (self), NULL); return self->priv->_text; }
Potential regression test for that issue: using GLib; interface Maman.Foo : GLib.Object { public abstract string! text { get; } } class Maman.Bar : GLib.Object, Maman.Foo { public virtual string! text { get { return "The Maman Bar"; } } static void main () { var bar = new Bar (); string text = bar.text; } }
Confirming.
Fixed in SVN r625. We enforce you now to transfer ownership with properties using non reference counting reference types. With reference counting types we use a hack in the getter decrementing the reference count before returning it which somehow simulates a weak reference. So your test needs to be rewritten into: using GLib; interface Maman.Foo : GLib.Object { public abstract string!# text { get; } } class Maman.Bar : GLib.Object, Maman.Foo { public virtual string!# text { get { return "The Maman Bar"; } } static void main () { var bar = new Bar (); string text = bar.text; } }