Subject: | buckets method appears to leak memory |
When repeatedly calling the buckets method the amount of memory consumed
by the process increases, so there appears to be a leak. Attached file
reproduces
Subject: | ketama_bucket_repro.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Algorithm::ConsistentHash::Ketama;
my $ket = Algorithm::ConsistentHash::Ketama->new();
$ket->add_bucket('test',1);
print "before:", join(", ", &memusage), "\n";
for (1..100_000){
$ket->buckets();
}
print "after: ", join(", ", &memusage), "\n";
exit 0;
#from http://www.perlmonks.org/?node_id=115098
sub memusage {
use Proc::ProcessTable;
my @results;
my $pid = (defined($_[0])) ? $_[0] : $$;
my $proc = Proc::ProcessTable->new;
my %fields = map { $_ => 1 } $proc->fields;
return undef unless exists $fields{'pid'};
foreach (@{$proc->table}) {
if ($_->pid eq $pid) {
push (@results, $_->size) if exists $fields{'size'};
push (@results, $_->pctmem) if exists $fields{'pctmem'};
};
};
return @results;
}