tigervamp has asked for the wisdom of the Perl Monks concerning the following question:
The amount of memory needed for the hash is 36MB (on my system). After the first block completes though, every other block increases the size of the memory being used by the program by a couple of MBs. However, when I add "undef" statements inside the blocks like so:{ my %hash; for my $i (1 .. 500000) { $hash{$i}=1; } } sleep 1; { my %hash; for my $i (1 .. 500000) { $hash{$i}=1; } } sleep 1; { my %hash; for my $i (1 .. 500000) { $hash{$i}=1; } } sleep 1; ...
this does not occur, the resident memory stays constant at 36 MB. My question is: Why is extra memory being used in the first example but not the second and is the latter scenerio the best way to handle this? I have tried this on Linux and SCO UNIX with perl 5.8 and 5.005_03 respectively, I think this is a perl thing. Any insight is greatly appreciated.{ my %hash; for my $i (1 .. 500000) { $hash{$i}=1; } undef %hash; } sleep 1; ...
Thanks,
tigervamp
|
---|