Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Memory issue with Hash

by flexvault (Prior)
on Dec 02, 2012 at 19:53 UTC ( #1006754=note: print w/ replies, xml ) Need Help??


in reply to Memory issue with Hash

Welcome nowise,

I had a similar problem about a year ago. I had a hash that just grew and grew and it turned out to be a scoping problem. I created the hash in the main script and was trying to clear it in a subroutine. What I cleared was an empty hash and returned to the main script without touching the 'real' hash.

If this isn't what your doing, then you'll have to show some code. The '%Hash' is very powerful and very reliable, so it's probably something your doing wrong. But that's how we learn.

Good Luck!

"Well done is better than well said." - Benjamin Franklin


Comment on Re: Memory issue with Hash
Replies are listed 'Best First'.
Re^2: Memory issue with Hash
by nowise (Initiate) on Dec 04, 2012 at 06:15 UTC

    In order to describe it more clearly , i have 1 example below, in which i have created 1 big hash-of-hash. Although i have put only 2 HOH inside %TV overhere ( just for clarity sake ), but in my code i have it 300 or more HOH ( while incrementing the key e.g jetsons1, jetsons2... ) in order to check the memory usage.

    #!/usr/bin/perl5.8 use Proc::ProcessTable; #use Tie::File::AsHash;
    my %hash= (); %TV = ( flintstones =>{ series => "flintstones", nights => [ qw(monday thursday friday) ], members => [ { name => "fred", role => " +lead", age => 36, }, { name => "wilma", role => " +wife", age => 31, }, { name => "pebbles", role => " +kid", age => 4, }, ], }, jetsons1 => { series => "jetsons", nights => [ qw(wednesday saturday) ], members => [ { name => "george", role => "l +ead", age => 41, }, { name => "jane", role => "w +ife", age => 39, }, { name => "elroy", role => "k +id", age => 9, }, ] },
    sub memory_use { my $t = new Proc::ProcessTable; foreach my $got ( @{$t->table} ) { next if not $got->pid eq $$; return $got->size; } }
    my $count = 10; my $key = 'test'; #tie %hash, 'Tie::File::AsHash', 'abc.csv', split => ':' or die "Pr +oblem tying %hash: $!"; foreach my $family (keys %TV) { $count++; my $record = ""; my $rec = $TV{$family}; my $key = $family . $rec->{series}; for $person ( @{ $rec->{members} } ) { $record .= $person->{name}."," . $person->{role}. "," . $person->{age} . "," . $rec->{series} . "," . $rec->{nights}[0]; } print "\n Key: $key \n"; print "\n Record: $record \n"; $hash{$key} = $record; if ( $count%10 == 0 ) { sleep(10 ); print "\n Record counter => [$count] \n"; print "\n Process Status:" . ( ( memory_use()/1024 )/1024 ) +."MB \n"; %hash = (); # if we comment it memory constant } } #----for 1----#

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006754]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2015-07-08 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls