Subject: | Proc::ProcessTable Leaks Memory |
When I use Proc::ProcessTable with code that calls fork() and exit(), my process leaks memory. When I use Devel::SizeMe instead, I see no leaks.
As far as I can tell, this happens due to a leak somewhere in Proc::ProcessTable.
I'm running Ubuntu 12.04.4 which uses Linux kernel 3.8.0-42.
The attached scripts demonstrate the leak with Proc::ProcessTable (fork_leak.pl) and the absence of the leak with Devel::SizeMe (fork_no_leak.pl).
Please let me know if I can provide more information to help resolve this problem.
Tom Hukins
Subject: | fork_leak.pl |
#!perl
use strict;
use warnings;
use List::Util 'first';
use Proc::ProcessTable ();
sub _do_a_fork {
my $pid = fork();
if ( $pid == 0 ) {
exit 0;
}
waitpid 1, $pid;
}
my $proc_table = Proc::ProcessTable->new;
foreach my $i (0 .. 1_000_000 ) {
unless ( $i % 100 ) {
my $process = first { $_->pid == $$ } @{ $proc_table->table };
print "Count $i Size ", $process->rss, "\n";
}
_do_a_fork();
}
Subject: | fork_no_leak.pl |
#!perl
use strict;
use warnings;
use List::Util 'first';
use Devel::SizeMe 'perl_size';
sub _do_a_fork {
my $pid = fork();
if ( $pid == 0 ) {
exit 0;
}
waitpid 1, $pid;
}
foreach my $i (0 .. 1_000_000 ) {
unless ( $i % 100 ) {
print "Count $i Size ", perl_size(), "\n";
}
_do_a_fork();
}