Re: gtk2-perl / a script to help converting basic functions



Guillaume Cottenceau <gc mandrakesoft com> writes:

The first test leaks memory probably because it calls
TextBuffer::get_bounds which create each time two Gtk2::TextIter
objects, and the last test leaks memory just by creating a new
button with no label...

I've discovered that we need the following to not leak memory
when returning back multiple values:

--- Gtk2/src/Calendar.c 20 Oct 2002 15:53:32 -0000      1.5
+++ Gtk2/src/Calendar.c 23 Oct 2002 14:36:56 -0000
@@ -40,5 +40,5 @@
     av_push(av, newSViv(year));
     av_push(av, newSViv(month));
     av_push(av, newSViv(day));
-    return newRV((SV*) av);
+    return newRV_noinc((SV*) av);
 }
 
Goran, have you looked at the problem of object destruction?

Ok, I've looked both at destructing gtk objects and non-gtk
objects (gtk structs).


For gtk objects, it seems that calling ``gtk_object_sink'' is
needed when destroying objects - but it only reduces half the
memory leak, I'm still investigating about the second half.


For gtk structs, I propose to add the following function in
_Helpers.c:

void gtk2_perl_g_free_associated_mem(SV* perl_obj)
{
    g_free(SvIV(SvRV(perl_obj)));
}

And making one package file per struct, which all inherit from
Gtk2::Struct, in which we put:

sub DESTROY {
    Gtk2::_Helpers::gtk2_perl_g_free_associated_mem(shift);
}


I've tested this on TextIter, it removes the entire memory
leaking.

WDYT?


-- 
Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/



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