My code looks like:
my %var;
my %var_new={};
while(1){
while(my ($k,$v)=each %var){
&a_sub($v);
}
%var={}; # A
map { $var{$_}=$var_new{$_}; } keys %var_new;
%var_new={}; # B
}
sub a_sub { #....} # will fill %var_new
My program’s memory usage goes up and up.
It seems Perl doesn’t free memory at Line A and Line B.
How can I manually make Perl to free up memory used %var and %var_new?
IIRC, once Perl has allocated memory from the operating system, it holds onto that memory for the life of the process. Where possible, Perl will reuse memory it has already allocated rather than ask the operating system for more, but you won’t see the memory used by a process decrease.