I concur. There is sustained and heavy memory allocation going on in the second loop for which I can see no apparent reason. There is no autovivification of hash elements occuring. You have discovered another memory leak and the culprit is join(*).
If you replace your second loop with
while ( my( $key1, $val1 ) = each %hash1 ) { while ( my( $key2, $val2 ) = each %$val1 ) { print( ##join( "\t", $key1, $key2, $hash1{ $key1 }{ $key2 }, $hash2{ $key1 }{ $key2 }, $hash3{ $key1 }{ $key2 } ); } }
The code runs to completion and shows zero memory growth during the second loop.
The problem also exists in 5.6.2. Raise a perlbug.
*Update: It's more complicated than just join. Seems it needs both join and a reference to a compound hash plus some unknown factor to cause the leak.
If you remove the join, or the hash reference, or make either of the keys a constant and the leak does not occur!
while ( my( $key1, $val1 ) = each %hash1 ) { while ( my( $key2, $val2 ) = each %$val1 ) { die 'Autovivify' unless exists $hash1{ $key1 } and exists $hash1{ $key1 }{ $key2 }; print( join "\t", $key1, $key2, $hash1{ $key1 }{ $key2 }, ); } }
In reply to Re: Memory Error Printing Multiple Hashes Simultaneously
by BrowserUk
in thread Memory Error Printing Multiple Hashes Simultaneously
by bernanke01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |