Subject: | Tk::Listbox leaks memory |
Tk::Listbox doesn't release memory after calling the delete method. This is particurly problematic in applications that continually deleted/insert Listbox items. The memory just keeps adding up until all system memory is full.
There are many widgets that rely on Tk::Listbox such as Tk::MListbox and Tk::Columns. This bug in Listbox effects all of these widgets.
You can see for yourself by running the attached script. Everytime the button is pressed the memory consumption will go up.
I have tested this on Fedora Core 2 and Windows 2000 using Perl 5.8.6 and the latest Tk version (804.027).
- Ken Prows
#!/usr/bin/perl -w
use strict;
use Tk;
my $mw = Tk::MainWindow->new(-title => 'Listbox Leak');
my $b = $mw->Button(-text => 'Leak', -command => \&leak)->pack(-side=>'bottom');
my $l = $mw->Scrolled('Listbox', -width=>10, -height=>20, -scrollbars=>'e',)->pack(-side=>'top',);
for(1..10000)
{
$l->insert('end', $_);
}
MainLoop;
sub leak
{
$l->delete(0,'end');
for(1..10000)
{
$l->insert('end', $_);
}
$l->update;
}