Perrin brings up a very good point.

I quickly ran a test that creates 3 hashes of the type and depth that you mentioned. Here's the ps command output:

PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22842 pts/1 R+ 0:00 0 10 6941 1680 0.1 perl xxx.pl create all the hashes PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22842 pts/1 S+ 0:23 2 10 932137 883884 85.5 perl xxx.pl clean out hashes PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22842 pts/1 R+ 0:30 31 10 932137 885632 85.6 perl xxx.pl we're done

Memory requirements of your program are likely to be at least 933 MBytes this is without DBI etc.!! Since you mentioned that your computer has 1GByte internal memory on board the sheer size of the hashes definitely will require the operating system to swap memory pages.
The Perl garbage collection is not the cause of this problem, even while it does require some time. The operating system takes time to memory swap things in good shape again.
So you may want to add a bit more internal memory to your system to run an application like this one ;-)

Test-program source:

#!/usr/bin/perl use strict;use warnings; sub showtime { print `ps -p $$ v`; } showtime; print "create all the hashes\n"; my %h1; foreach my $one (0..64000) { $h1{$one}={}; foreach my $two (0..2) { $h1{$one}{$two}='foo'; } } my %h2; foreach my $one (0..2200000) { $h2{$one}={}; foreach my $two (0..3) { $h2{$one}{$two}='foo'; } } my %h3; foreach my $one (0..1) { $h3{$one}={}; foreach my $two (0..1) { $h3{$one}{$two}={}; foreach my $three (0..1) { $h3{$one}{$two}{$three}={}; foreach my $four (0..9) { $h3{$one}{$two}{$three}{$four}={}; foreach my $five (0..14) { $h3{$one}{$two}{$three}{$four}{$five}={}; foreach my $six (0..39) { $h3{$one}{$two}{$three}{$four}{$five}{$six}='bar'; } } } } } } showtime; print "clean out hashes\n"; %h1= (); %h2= (); %h3= (); showtime; print "we're done\n";

In reply to Re^2: Perl cleanup takes a long time by varian
in thread Perl cleanup takes a long time by ChrisR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.