N
Nikki R
Hi,
I'm running a Perl script on Linux Red Hat 7.3 (in a company - I can't
upgrade).
My script uses up a lot of memory because it is reading large data files.
The largest file is about 10MB.
The data files were stored by using Data:
umper, and my script reads each
data file one at a time:
foreach .... {
my $var1;
# Suck in the entire Data:
umper'd file.
my $filestr = join('', <SOMEFILE>);
# The Data:
umper file consists of a statement like:
# $var1 = {....} ; # Large hash reference.
eval $filestr;
# That sets $var1 which is a hash reference. Now do something with
$var1.
....
}
As the script runs, memory grows fairly quickly. I don't think have a
memory leak anywhere - I think that Perl allocates new memory whenever
it sees a larger data file than previously.
That's my understanding of the way Perl's garbage collection works, anyway.
In the above loop even though all of the 'my' variables go out of scope,
Perl doesn't normally release any memory back to the operating system until
the script finishes running.
Is there anything I can do about this, e.g. change the way that the data
file is read in? I definitely need to use a hash and I don't have the
choice
of using anything else but Data:
umper (this is part of a large project
that I cannot change).
Is there also a good way of finding out (via a tracer or profiler of
some sort perhaps) which variables are using how much memory in a Perl
script? I eventually found out the above culprits only by doing a fair
amount of analysis using the Perl debugger and using Unix's "top"
program to see how much memory my perl script was using in total.
I'm running a Perl script on Linux Red Hat 7.3 (in a company - I can't
upgrade).
My script uses up a lot of memory because it is reading large data files.
The largest file is about 10MB.
The data files were stored by using Data:
data file one at a time:
foreach .... {
my $var1;
# Suck in the entire Data:
my $filestr = join('', <SOMEFILE>);
# The Data:
# $var1 = {....} ; # Large hash reference.
eval $filestr;
# That sets $var1 which is a hash reference. Now do something with
$var1.
....
}
As the script runs, memory grows fairly quickly. I don't think have a
memory leak anywhere - I think that Perl allocates new memory whenever
it sees a larger data file than previously.
That's my understanding of the way Perl's garbage collection works, anyway.
In the above loop even though all of the 'my' variables go out of scope,
Perl doesn't normally release any memory back to the operating system until
the script finishes running.
Is there anything I can do about this, e.g. change the way that the data
file is read in? I definitely need to use a hash and I don't have the
choice
of using anything else but Data:
that I cannot change).
Is there also a good way of finding out (via a tracer or profiler of
some sort perhaps) which variables are using how much memory in a Perl
script? I eventually found out the above culprits only by doing a fair
amount of analysis using the Perl debugger and using Unix's "top"
program to see how much memory my perl script was using in total.