Memory leak in Gtk?
- From: Joern Reder <joern netcologne de>
- To: gtk-perl-list gnome org
- Subject: Memory leak in Gtk?
- Date: Tue, 20 Nov 2001 23:18:25 +0100
Hi,
I'm using Gtk::Gdk::ImlibImage in conjunction with a Gtk::DrawingArea to
draw a Gtk::Gdk::Pixmap (an some lines and stuff on it, later).
If I load a new image file to draw on the DrawingArea, the process
consumpts memory very fast (about 2 MB per file).
Here is a test program which demonstrates this effect:
--snip--
#!/usr/local/bin/perl
use strict;
use Gtk;
use Gtk::Gdk::ImlibImage;
Gtk->init;
Gtk::Gdk::ImlibImage->init;
# unfortunately useless...
Gtk::Gdk::ImlibImage->set_cache_info (0, 0);
use File::Copy;
use File::Basename;
main: {
my $filename = shift @ARGV;
if ( not $filename ) {
print "usage: leak.pl filename\n";
exit 1;
}
my $win = Gtk::Window->new ( -toplevel );
$win->set_position ('center');
$win->signal_connect( 'destroy', sub { Gtk->exit( 0 ); } );
$win->show;
my $da = Gtk::DrawingArea->new;
$da->show;
$da->size (256,256);
my $gdk_pixmap = load ($filename);
$da->signal_connect( 'configure_event', sub { draw ($da, $gdk_pixmap) } );
$da->signal_connect( 'expose_event', sub { draw ($da, $gdk_pixmap) } );
my $vbox = Gtk::VBox->new;
$vbox->show;
$vbox->pack_start ($da, 0, 1, 0);
my $button = Gtk::Button->new_with_label ("click me for memory leak");
$button->show;
$vbox->pack_start ($button, 0, 1, 0);
$button->signal_connect ("clicked", sub {
$gdk_pixmap = load ($filename);
draw ($da, $gdk_pixmap);
});
$win->add($vbox);
Gtk->main;
}
sub load {
my $filename = shift;
# prevent caching (worst hack!)
my $tmp_name = "/tmp/imageclip$$".rand(1000000).basename($filename);
copy ($filename, $tmp_name);
my $image = Gtk::Gdk::ImlibImage->load_image ($tmp_name);
unlink $tmp_name;
$image->render (256, 256);
return $image->copy_image; # same effect with ->move_image
}
sub draw {
my ($da, $gdk_pixmap) = @_;
my $drawable = $da->window;
my $white_gc = $da->style->white_gc;
$drawable->draw_pixmap (
$white_gc, $gdk_pixmap, 0, 0, 0, 0, 256, 256
);
return 1;
}
--snip--
Is this a bug in my program? Or is Gtk leaking here...
Thanks for your help,
Joern
--
sub i($){print$_[0]}*j=*ENV;sub w($){sleep$_[0]}sub _($){i"$p$c > ",w
1,$_=$_[0],tr;i-za-h,;a-hi-z ;,i$_,w 1,i"\n"}$|=1;$f='HO';($c=$j{PWD}
)=~s/$j{$f."ME"}/~/;$p="$j{USER}\ $j{HOSTNAME}:";_"kl",$c='~',_"zu,".
"-zn,*",_"#,epg,lw,gwc,mfmkcbm,cvsvwev,uiqt,kwvbmvb?",i"$p$c > ";w 99
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]