Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl # # SSCCE that demonstrates a problem encountered with # Memoize 1.03 in old Perl. Tested successfully on Perl # 5.20.3 to 5.28.0 where a ~2.6M cache is created. # When run under Perl 5.18 on Mac OSX the cache grows # to gigabytes and the program never seems to exit. # Unsure if the problem is Perl, the module or OSX. use strict; use warnings; use Carp; use DB_File; use Memoize; use POSIX (); my $cache = 1; my @subs = qw(two ten); for my $sub (@subs) { my $file = $] . '_memoized_' . $sub; if ($cache) { no strict 'refs'; if (my $db = tie %{$sub} => 'DB_File', $file, POSIX::O_RDWR|POSIX: +:O_CREAT, 0666) { memoize $sub, SCALAR_CACHE => [HASH => \%{$sub}]; } else { croak 'memo fail' } } } for my $n ('1' .. '100000') { $n = two($n); $n = ten($n); print "\r$n\t" } sub two { my $n = shift; $n = $n * 2; return $n } sub ten { my $n = shift; $n = $n * 10; return $n }

Replies are listed 'Best First'.
Re: Gigantic Memoize Cache Problem
by Anonymous Monk on Oct 26, 2018 at 15:57 UTC
      It passes on darwin 13 and 14 but fails on 16. I have 17.5.0 which also fails. Looks like a new bug in OSX :-(