Wednesday, 7 August 2013

perl memory leak or usage

perl memory leak or usage

i have a perl module that runs in the system for the entire life (like a
process). This module is used by some other process to push data. When the
data comes into the perl module, it is processed and written to a file.
The perl module is not supposed to save any data within the program
itself.
What I see is, everytime I push data (with some new addition or deletion
of previous data), I see the memory usage of this module going up and
never released. I went through lot of threads online about
hash/array/string/variable memory not getting cleaned up. Question I have
is, the local variables/hashes/strings/arrays inside a sub (also for
global variables), do they take memory everytime the module processes the
data? The processing is same irrespective of whether new data is added or
some data is removed. When I saw new data added, it also includes the
previous data. for example if the data sent 1st time is x=10, second time
if new data is added ie y=15, the module sees x=10 and y=15.
BTW, the input is a json with x:10, y:15 etc...
the code is something like this
Readonly my $localfile => "dad";
sub a {
my $ad = @_;
my $h;
my $file = $localfile;
my $out = gensym();
open($out, '>', $file);
...
my @orders = ('a', 'b', 'c', 'd', 'e');
my $rule;
foreach my $f (@orders) {
$rule = 0;
$h = $ad->{$f};
if (defined($h)) {
my $fh = $ad->{$f}{'doit'};
($config, $ruleIndex) = &$fh($h, $out, $rule, $ad);
getIt($h, $out);
}
}
my $fg = {};
while (my ($t, $fg) = each %$Q) {
my $n = $Data->{$t};
if (defined($n)) {
$fg->{$t} = $n;
}
}
close $out;
return $fg;
Appreciate the help

No comments:

Post a Comment