ldln has asked for the wisdom of the Perl Monks concerning the following question:

What is required to free up memory used by Tk::TableMatrix when data in table is deleted (or get it to reuse the memory it has already consumed) instead of just grabbing more and more memory?

In test script below we fill up table with data. When table is emptied memory usage stays the same (about 138_000 KB) and when we fill up table again with new data, memory just increases more and more.. Hopefully I just missed the boat somewhere.


Thanks for advice.

use warnings; use strict; use Tk; use Tk::TableMatrix::Spreadsheet; $| = 1; my $mw = tkinit; my $NumCols = 50; our $tmVar = {}; our $TM_Table = $mw->Scrolled('Spreadsheet', -variable => $tmVar, -sparsearray=>1, -titlerows => 1, -titlecols => 1, -scrollbars => 'se', -selectmode => 'extended', -rows=>1, -cols=> $NumCols, -resizeborders => 'both', -wrap=>1, -bd=>1, -cache=>0, -selecttitle=>1, -colstretchmode => 'none', -rowstretchmode => 'none', -rowheight => 1, -drawmode=>'fast')->pack(-expand=>1,-fill=>'both'); $mw->Button(-text=> 'Fill Tablematrix', -command => \&FillTM)->pac +k; $mw->Button(-text=> 'Clear Tablematrix', -command => \&ClearTM)->p +ack; #Top row $TM_Table->set("0,$_", $_) for (0..$NumCols-1); MainLoop; sub FillTM { my $Rows = 5000; $TM_Table->insertRows("0.0", $Rows); for my $Row (1..5000) { $mw->update if (not $Row % 500) xor $TM_Table->see("$Row,0"); for (0..$NumCols-1){ $TM_Table->set("$Row,$_",qw(111 222)[int rand 2] x 50 ); } } } sub ClearTM { #$TM_Table->deleteRows('-keeptitles', '0.0', $TM_Table->cget(-rows +)); $TM_Table->deleteRows( '0.0', $TM_Table->cget(-rows)); $TM_Table->clearAll('0,0','end'); undef $tmVar; }