memory leaks with Tk::Canvas

Christophe Mertz <[email protected]>
Newsgroups gmane.comp.lang.perl.tk
Organization IntuiLab
Message-ID <1106932988.3661.101.camel@datura>
[sorry, for the re-send... with the attached script this time]

Hello,

we have some memory leaks in one of our (relatively big) interactive
application based on perl/Tk (and zinc!). After some inquiry we finally
detects some leaks in Tk::Canvas

In the attached simple script I reproduce apparently two different
leaks:

1) when clicking repeatedly on the blue button (ie without waiting the
end of the "animation"), it seems there is a leak or 132kB (linux ptk
804.027) or 4kb (win activestate 804.027)


2) when clicking even once on the red button, there seems to be strong
leak of approx 132kB on linux 804.027 but none (or few?) on windows
(activestate 804.027)
This bug appears when we replace an array in a coords method by the
corresponding "tk" string.


Does someone identify some similar leaks on ptk 804 ? 

Does someone have a clue?

Cheers,

-- Christophe Mertz
canvas.pl (text/x-perl, 1.5 KB)
#!/usr/bin/perl -w
use Tk;
use Tk::Canvas;


my $mw = MainWindow->new();
$mw->geometry('1024x768');
my $canvas = $mw->Canvas(-width => 1024, -height => 768) -> pack();


my $rect = $canvas->create('rectangle', [0, 0, 0, 0]);

my $bt1 = $canvas->create('rectangle', [20, 20, 50, 50],
		     -fill => 'blue');

my $bt2 = $canvas->create('rectangle', [20, 100, 50, 130],
		     -fill => 'red');


$canvas->bind($bt1, '<1>',sub{anim1();});
$canvas->bind($bt2, '<1>',sub{anim2();});

my $count =0;

MainLoop;

my $cfor = 0;

## bug1
## click repeteadly on blue rectangle so that more
## than one such callback is runned at the same time
sub anim1 {
   my $c = ++$cfor;
   print "begin anim1: $c\n";
   for (my $i = 0; $i < 800; $i++){
     $canvas->coords($rect,[0, 0, $i, $i]);
     $canvas->update();
   }
   print "end anim1: $c\n";
}

# bug #2
# this code leaks approx 264 kB every time it is called
sub anim2 {
   my $c = ++$cfor;
   print "begin anim2: $c\n";
   for (my $i = 0; $i < 800; $i++){

     # using a string rather than the usual perl array
     $canvas->coords($rect,"0 0 $i $i");
     $canvas->update();
   }
   print "end anim2: $c\n";
}


## the following code does not leak if activated only once
## (ie no successive click on the green rectangle)
sub anim3 {
   my $c = ++$cfor;
   print "begin anim3: $c\n";
   for (my $j = 0; $j < 100; $j++) {
     for (my $i = 0; $i < 800; $i++){
       $canvas->coords($rect,[0, 0, $i, $i]);
       $canvas->update();
     }
   }
   print "end anim3: $c\n";
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.