Memory leaks in List::MoreUtils' each_array() and each_arrayref()?
I have just discovered a nasty memory leak using both each_array() and each_arrayref() from List::MoreUtils.
These three lines of code are part of a subroutine executed four thousand times on each run. My objective is to give proper format to values already in a hash. I have a fixed number of hash keys and a format string for each hash key.
my %hash = ();
# ...
my $two_arrays = each_arrayref( $field_list, $field_list_format );
while ( my ( $field, $format ) = $two_arrays->() ) {
$hash{ $field } = sprintf $format, $hash{ $field };
}
If I stick a return;
before my $two_arrays ...
, the leak disappears. The same return;
past the last line makes the leak.
Since the subr开发者_StackOverflow中文版outine is part of a daemon program, I noticed the continuous growth of memory ( both VIRT and RES ).
There is something I did wrong? Is there is any memory leak of each_array() or each_arrayref(), I'm not aware of?
- List::MoreUtil ( VERSION 0.22 )
- Perl 5.12.1 ( x86_64 with threads ) on Linux 2.6.32-32-generic ( Ubuntu 10.04 )
List::MoreUtil ( VERSION 0.22 ) is dated July 2006, 5 years ago. The current version is 0.32, is the leak still present in this version? There have been several memory leaks fixed in the last few versions: http://cpansearch.perl.org/src/ADAMK/List-MoreUtils-0.32/Changes
精彩评论