Re: Gdk Pixbufloader not freeing memory




Hi,

didn't check the details, but I attached two mails from the list I 
posted some time ago with a similar problem (and a solution ;)

Probably it helps.

Regards,

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
Return-Path: <gtk-perl-list-admin gnome org>
Received: from localhost (localhost [127.0.0.1])
        by prison.castle (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id fAKMQ4c15207
        for <joern localhost>; Tue, 20 Nov 2001 23:26:04 +0100
Received: from mail.netcologne.de [194.8.194.109]
        by localhost with POP3 (fetchmail-5.6.0)
        for joern localhost (single-drop); Tue, 20 Nov 2001 23:26:04 +0100 (CET)
Received: from mr200.netcologne.de (mr200.netcologne.de [194.8.194.109])
        by mailstore2.netcologne.de (Mirapoint)
        with ESMTP id ABF00469;
        Tue, 20 Nov 2001 23:19:42 +0100 (CET)
Received: from mail.gnome.org (moniker.gnome.org [209.116.70.73])
        by mr200.netcologne.de (Mirapoint)
        with ESMTP id AQG51187;
        Tue, 20 Nov 2001 23:19:41 +0100 (CET)
Received: from moniker.gnome.org (moniker.gnome.org [127.0.0.1])
        by mail.gnome.org (Postfix) with ESMTP
        id 65ED8183DF; Tue, 20 Nov 2001 17:19:37 -0500 (EST)
Delivered-To: gtk-perl-list gnome org
Received: from prison.castle (pD9E3F83D.dip.t-dialin.net [217.227.248.61])
        by mail.gnome.org (Postfix) with ESMTP id C5E7118308
        for <gtk-perl-list gnome org>; Tue, 20 Nov 2001 17:18:31 -0500 (EST)
Received: from wizard.castle (wizard.castle [192.168.42.66])
        by prison.castle (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id fAKMIPc15148
        for <gtk-perl-list gnome org>; Tue, 20 Nov 2001 23:18:29 +0100
Message-Id: <200111202218 fAKMIPc15148 prison castle>
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
To: gtk-perl-list gnome org
From: Joern Reder <joern netcologne de>
Subject: Memory leak in Gtk?
X-Mailer: JaM - Just a Mailer (Highly Secure Personal Free Highspeed
    Archiving Gtk Perl Mailer Against Micro$oftism) v1.0.9
Sender: gtk-perl-list-admin gnome org
Errors-To: gtk-perl-list-admin gnome org
X-BeenThere: gtk-perl-list gnome org
X-Loop: gtk-perl-list gnome org
X-Mailman-Version: 2.0.6
Precedence: bulk
List-Help: <mailto:gtk-perl-list-request gnome org?subject=help>
List-Post: <mailto:gtk-perl-list gnome org>
List-Subscribe: <http://mail.gnome.org/mailman/listinfo/gtk-perl-list>,
        <mailto:gtk-perl-list-request gnome org?subject=subscribe>
List-Id: Using GTK+ with Perl <gtk-perl-list.gnome.org>
List-Unsubscribe: <http://mail.gnome.org/mailman/listinfo/gtk-perl-list>,
        <mailto:gtk-perl-list-request gnome org?subject=unsubscribe>
List-Archive: <http://mail.gnome.org/archives/gtk-perl-list/>
Date: Tue, 20 Nov 2001 23:18:25 +0100
X-UIDL: I(="!632"!]YL"!OG~"!


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
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Return-Path: <gtk-perl-list-admin gnome org>
Received: from localhost (localhost [127.0.0.1])
        by prison.castle (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id fAL447c17378
        for <joern localhost>; Wed, 21 Nov 2001 05:04:08 +0100
Received: from mail.netcologne.de [194.8.194.109]
        by localhost with POP3 (fetchmail-5.6.0)
        for joern localhost (single-drop); Wed, 21 Nov 2001 05:04:08 +0100 (CET)
Received: from mr200.netcologne.de (mr200.netcologne.de [194.8.194.109])
        by mailstore2.netcologne.de (Mirapoint)
        with ESMTP id ABF02559;
        Wed, 21 Nov 2001 00:10:12 +0100 (CET)
Received: from mail.gnome.org (moniker.gnome.org [209.116.70.73])
        by mr200.netcologne.de (Mirapoint)
        with ESMTP id AQG56659;
        Wed, 21 Nov 2001 00:10:11 +0100 (CET)
Received: from moniker.gnome.org (moniker.gnome.org [127.0.0.1])
        by mail.gnome.org (Postfix) with ESMTP
        id 9FB3A18B86; Tue, 20 Nov 2001 18:10:07 -0500 (EST)
Delivered-To: gtk-perl-list gnome org
Received: from prison.castle (pD9E3F83D.dip.t-dialin.net [217.227.248.61])
        by mail.gnome.org (Postfix) with ESMTP id A3F8018B7E
        for <gtk-perl-list gnome org>; Tue, 20 Nov 2001 18:09:25 -0500 (EST)
Received: from wizard.castle (wizard.castle [192.168.42.66])
        by prison.castle (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id fAKN9Lc15320
        for <gtk-perl-list gnome org>; Wed, 21 Nov 2001 00:09:21 +0100
Message-Id: <200111202309 fAKN9Lc15320 prison castle>
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
In-Reply-To: <200111202218 fAKMIPc15148 prison castle>
To: gtk-perl-list gnome org
From: Joern Reder <joern netcologne de>
Subject: Solved (was: Re: Memory leak in Gtk?)
X-Mailer: JaM - Just a Mailer (Highly Secure Personal Free Highspeed
    Archiving Gtk Perl Mailer Against Micro$oftism) v1.0.9
Sender: gtk-perl-list-admin gnome org
Errors-To: gtk-perl-list-admin gnome org
X-BeenThere: gtk-perl-list gnome org
X-Loop: gtk-perl-list gnome org
X-Mailman-Version: 2.0.6
Precedence: bulk
List-Help: <mailto:gtk-perl-list-request gnome org?subject=help>
List-Post: <mailto:gtk-perl-list gnome org>
List-Subscribe: <http://mail.gnome.org/mailman/listinfo/gtk-perl-list>,
        <mailto:gtk-perl-list-request gnome org?subject=subscribe>
List-Id: Using GTK+ with Perl <gtk-perl-list.gnome.org>
List-Unsubscribe: <http://mail.gnome.org/mailman/listinfo/gtk-perl-list>,
        <mailto:gtk-perl-list-request gnome org?subject=unsubscribe>
List-Archive: <http://mail.gnome.org/archives/gtk-perl-list/>
Date: Wed, 21 Nov 2001 00:09:21 +0100
X-UIDL: Z4&"!?_5!!TSY"!-]&#!

Joern Reder wrote:

Is this a bug in my program? Or is Gtk leaking here...

It was a bug of mine - after crawling through the documentation again, I
found this

  (Gtk::Gdk::ImlibImage) $image->kill_image

And yes: it does what it sounds like ;)

I call this after getting the pixmap with $image->copy_image: and 
nothing is leaking anymore.

Joern

-- 
Joern Reder - joern zyn de
Development Head ZYN! Coding Division - http://www.zyn.de/joe
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list



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