Gtk::Gdk::Pixbuf / Pixmap leaks memory and is broken


I found problem with Gtk::Gdk::Pixbuf (or with my code anyway).

I am writting an application to play with sample signal and
plot it.

Just for fun I started to plot the graphics on each 
interation (which looks like an animation).

however the memory of the X server and the gtk program
just increases.

the leak of memory is probably occuring with the Pixbuf[Loader]
or with Gtk::Pixmap->set which should unref the previously used

In C the code should unref the Gdk Pixmap, before using set().
In Perl this should happen automagically by the bidings.

There was a discussion about this before and Paolo state that
this has being fixed.  If so, the problem is with Pixbuf.

In the code, GD is used to generate the chart.
If you change it to something smaller, the PNG image is 
generated, however Pixbuf breaks with:

Can't call method "render_pixmap_and_mask"on an undefined value.

Because it does not recognize the image.

I am using perl 5.6.1, 
compiled with gcc 2.95.4
Gtk-Perl 0.7008
GD 1.35

Anyone knows something about this situation?

Raul Dias

here is a sample code:

use Gtk;
use Gtk::Gdk::Pixbuf;
use GD;

init Gtk;

our $PIXMAP;

my $window = new Gtk::Window("toplevel");
$window->signal_connect( "delete_event", sub { Gtk->exit(0)}  );

my $vbox = new Gtk::VBox(0,1);

my $image = new GD::Image( 900 ,100);
my $black = $image->colorAllocate(0,0,0);
my $white = $image->colorAllocate(255,255,255);
$image->rectangle(0,1,10,10, $white);
our $png = $image->png;

$PIXMAP = png2pixmap($png);

Gtk->timeout_add(3000, sub {
                   for (0..10){
                     print "loop: $_\n";
                     main_iteration Gtk while Gtk->events_pending;
                   return 1;

main Gtk;

sub png2pixmap {
  my ($image,$pos) = @_;

  my $loader = new Gtk::Gdk::PixbufLoader;
  my $pixbuf = $loader->get_pixbuf;
  my ($gdkpixmap, $mask) = $pixbuf->render_pixmap_and_mask(0);

  if (defined $pos) {
    $PIXMAP->set($gdkpixmap, $mask);
  } else {
    my $pixmap = new Gtk::Pixmap ($gdkpixmap, $mask);
    return $pixmap;

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