in reply to Memory Error Printing Multiple Hashes Simultaneously
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 }, ); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Memory Error Printing Multiple Hashes Simultaneously
by bernanke01 (Beadle) on Jan 31, 2006 at 16:59 UTC | |
by BrowserUk (Patriarch) on Jan 31, 2006 at 17:37 UTC |