GdkPixbuf leaks memory
- From: Dov Grobgeld <dov Orbotech COM>
- To: gtk-perl-list gnome org
- Subject: GdkPixbuf leaks memory
- Date: Fri, 4 May 2001 10:06:55 +0300
Hello,
I have during the last couple of days been hunting for a memory leak
connected to GdkPixbuf. It turns out that the perl bindings of a
GdkPixbuf never frees up the Pixbuf. It has something to do with the
reference counting of the Pixbuf, though I don't fully understand how.
To check this I added the following ugly xs function to GdkPixbuf.
int
gdk_pixbuf_get_refcount (pixbuf)
Gtk::Gdk::Pixbuf pixbuf
CODE:
RETVAL = *(int*)pixbuf;
OUTPUT:
RETVAL
(By inspecting the private section of the GdkPixbuf, I found that the
reference count is the first integer in the private section.)
Now if I in a perl program do the following:
$pb = new_from_file Gtk::Gdk::Pixbuf($file);
print "Refcount = ", $pb->get_refcount(),"\n";
The answer I get is:
Refcount = 2
In the DESTROY function that may be found in the GdkPixbuf.c after the
conversion from xs, there is only one call to gdk_pixbuf_unref().
Since memory is only freed up when the reference count goes to zero,
the memory is never freed up.
But I must admit I don't understand why the refcount got increased to
2. There are no further calls to gdk_pixbuf_ref() in the C-code. And
I also don't understand why I have to call DESTROY manually? Shouldn't
it be called manually when the perl variable is undef'd?
In the end I made a work around by manully adding another
gdk_pixbuf_unref() in the C-code. But that is obviously not the way to
do it...
Does someone with more experience with xs-code and gtk have any idea
of what is going on??
Btw, all these tests were done on Gtk-Perl-0.7006 from CPAN.
Regards,
Dov
--
Disclaimer: All views above are mine alone.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]