Subject: | Memory Leak |
Date: | Tue, 3 Feb 2015 16:47:04 -0800 |
To: | bug-AnyEvent-Process [...] rt.cpan.org |
From: | Bob Kleemann <bob.kleemann [...] tealium.com> |
It appears that AnyEvent::Process has a memory leak. While running the
following, I get a definite increase in the size of memory (about 7-8 MB)
used by Perl:
#! /usr/bin/env perl
use v5.18;
use AnyEvent;
use AnyEvent::Process;
use Errno qw(:POSIX);
use Devel::SizeMe qw(perl_size);
say perl_size;
for ( 1 .. 1_000_000 )
{
my $arg = rand;
my ( $stdout, $stderr ) = ( '', '' );
my $cv = AnyEvent->condvar;
my $run = AnyEvent::Process->new()->run(
args => [ $arg ],
code => sub { exec 'echo', @_ },
kill_interval => 10,
on_completion => sub {
my ( $job, $exit ) = @_;
$cv->send($exit);
},
on_kill => sub {
my $job = shift;
$job->kill(9);
$cv->send(-1);
},
fh_table => [
#\*STDIN => [ qw( open < /dev/null ) ],
\*STDOUT => [
qw( pipe > handle ),
[
on_eof => sub { }, # Ignore EOF
on_read => sub { $stdout = $_[0]->rbuf },
on_error => sub {
return if $! == EPIPE;
},
]
],
\*STDERR => [
qw( pipe > handle ),
[
on_eof => sub { }, # Ignore EOF
on_read => sub { $stderr = $_[0]->rbuf },
on_error => sub {
return if $! == EPIPE;
},
]
],
],
);
my $return = $cv->recv;
die $return if $return;
$run->close;
undef $run;
#undef $cv;
say perl_size unless $_ % 1_000;
}
say perl_size;