Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 12466
Status: resolved
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: ken.prows#online-rewards.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 804.027
Fixed in: 804.027_500



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; }
On Fri Apr 29 10:24:20 2005, guest wrote: Show quoted text
> 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
It seems that the attached patch fixes the problem. At least the memory increase is now MUCH smaller. Regards, Slaven
=== objGlue.c ================================================================== --- objGlue.c (revision 1211) +++ objGlue.c (local) @@ -844,8 +844,8 @@ int i; if (first < 0) first = 0; - if (first > len) - first = len; + if (first >= len) + first = len; /* So we'll insert after last element. */ if (first + count > len) count = first-len; newlen = len-count+objc; @@ -862,6 +862,11 @@ } else if (newlen < len) { + /* Delete array elements which will be sliced away */ + for (i=first; i < first+count; i++) + { + av_delete(av,i,0); + } /* Move entries beyond old range down to new location */ for (i=first+count; i < len; i++) {