Thank you all, for the help.
I think I have a revelation. My initial Perl/Tk application was to open a file, read it, do some calculations on the data and then write a new file.
There are a few parameters that one can choose in the application and I was thinking of changing a few parameters and run the same application without closing it. Then again, there was quite a big memory build up.
Initially I thought that the memory leak was coming from the ProgressBar or the
update method I was using. When I upgraded the Tk ver, the memory leak associated with the ProgressBar dissapeared, but the memory build up in my application stayed pretty much the same.
I managed to trace it down, and it is coming from the reading of the file itself.
Here is a example application:
#!/usr/bin/perl
use strict;
use warnings;
use Tk::Carp qw/fatalsToDialog/;
use Tk::Carp qw/warningsToDialog/;
use Tk;
my (
$in_file_name,
$out_file_name,
$MW,
$message,
$count_runs
);
$MW = MainWindow->new(-title=>"Open/read times");
my $Frame=$MW->Labelframe(
-text => 'Input Parameters',
)->pack();
my $Ent_In_File_Name=$Frame->Entry(
-textvariable => \$in_file_name,
)->grid(
-row => 0,
-column => 0,
-sticky => 'w',
);
my $Btn_Open_File=$Frame->Button(
-command => 'main::open_file',
-text => 'Open File',
)->grid(
-row => 0,
-column => 1,
-sticky => 'w',
);
my $Btn_run=$Frame->Button(
-command => 'main::run_program',
-text => 'Run program',
)->grid(
-row => 3,
-column => 0,
-sticky => 'w',
);
my $Ent_Run=$Frame->Entry(
)->grid(
-row => 3,
-column => 1,
-sticky => 'w',
);
###### SUBROUTINES ###################################################
+##########
sub open_file {
my $file_name_open=$MW->getOpenFile();
$Ent_In_File_Name->delete(0,'end');
$Ent_In_File_Name->insert(0,$file_name_open);
}
sub run_program {
$count_runs++;
my @data;
open MYFILE ,$in_file_name or die "Could not open file to read:$in
+_file_name\n";
while(<MYFILE>) {
my $temp=$_;
chomp $temp;
my @array=split("\t",$temp);
push(@data,[@array]);
}
close MYFILE;
$Ent_Run->delete(0,'end');
$Ent_Run->Insert("open/read N:$count_runs");
}
MainLoop();
The file is a Tab delimeted text file (~15Mb).
The strange thing is that every time I run this simple thing (Hit Run program button without closing the application), there is a memory leak of about 700-800Kb.
I tried the same thing with a simple perl script:
#!/usr/bin/perl
use warnings;
use strict;
my $in_file="\\in_file\.txt";
my $count_runs=0;
while (1) {
$count_runs++;
my @data;
open MYFILE ,$in_file or die "Could not open file to read:$in_file
+\n";
while(<MYFILE>) {
my $temp=$_;
chomp $temp;
my @array=split("\t",$temp);
push(@data,[@array]);
}
close MYFILE;
print "run $count_runs\n";
<>;
}
The result, no leak at all.
I am quite surprised here. Should'nt the local vars declared with
my be cleared when it goes out of scope???
It seems that this is only associated with Tk, but not Perl itself.
I just donot know what is going on here.
Any help would be appreciated. It is just bizzare.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.