Hi,
I'm working on a perl/Tk program that contains a Tk::Notebook were regularly tabs (or 'pages' as they are called in the documentation) are added and deleted. I've noticed everytime a tab is added and deleted my memory usage goes up, so I've reduced the problem to this piece of code:
#!/usr/bin/perl
use strict;
use warnings;
$| = 1;
use Tk;
use Tk::NoteBook;
use Devel::Size qw(total_size);
use Data::Dumper;
my $mw = MainWindow->new();
my $nb = $mw->NoteBook()->pack;
my $i;
my $amount = $ARGV[0];
$amount ||= 20;
print "0 tabs:\n";
print "total_size " . total_size($nb) . "\n";
print Dumper($nb);
print "\n-------------\n";
for ($i=0;$i<$amount;$i++) {
my $p1 = $nb->add("$i", -label => "$i");
$p1->Label(-text => "aap" x 100)->pack();
}
for ($i=0;$i<$amount;$i++) {
$nb->delete($i);
}
print "0 tabs: (after removing $amount tabs)\n";
print "total_size " . total_size($nb) . "\n";
print Dumper($nb);
print "\n-------------\n";
##MainLoop();
When I run this code on my PC (FreeBSD4.9 perl5.8.2 Tk804.025 (also tried Tk804.027 but same results)) after adding and removing tabs the memory usage of the Tk::Notebook increases, and the Data::Dumper output shows the '_names_'-hash inside of the blessed Tk::NoteBook-hash still contains the names of the tabs I deleted, so this obviously still takes up some memory.
This raises a lot of questions for me:
- Is this intended behaviour, or is this an unintended side-effect? Is there a workaround for this?
- I've tried to dig deeper into this problem, I can see Tk::Notebook uses Tk::NBFrame which in it's turn is XS-code. At that point I get lost. Any directions for debugging XS-code for people who haven't written XS-code before?
- On my PC Devel::Size prints out the warning 'CV isn't complete' when using the total_size function on the Tk::Notebook. Anybody knows what can cause a 'code value' to be incomplete?