Subject: | Memory/CPU leak with fast requeued timers |
$ cat loop-timer-memleak.pl
use strict;
use warnings;
use IO::Async::Loop;
my $loop = new IO::Async::Loop;
sub ioasync
{
$loop->enqueue_timer( delay => 0, code => $_[0] );
}
my $id;
sub cb
{
$id = ioasync \&cb;
}
my $count = 0;
while(1) {
$id = ioasync \&cb;
$loop->loop_once;
system "ps v $$" unless ++$count % 100;
}
$ perl -Mblib loop-timer-memleak.pl
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
9136 pts/11 S+ 0:01 0 1392 8975 5064 0.1 perl -Mblib
loop-timer-memleak.pl
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
9136 pts/11 S+ 0:06 0 1392 9107 5156 0.1 perl -Mblib
loop-timer-memleak.pl
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
9136 pts/11 S+ 0:14 0 1392 9107 5196 0.2 perl -Mblib
loop-timer-memleak.pl
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
9136 pts/11 S+ 0:26 0 1392 9107 5240 0.2 perl -Mblib
loop-timer-memleak.pl
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
9136 pts/11 S+ 0:41 0 1392 9239 5340 0.2 perl -Mblib
loop-timer-memleak.pl
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
9136 pts/11 S+ 1:01 0 1392 9239 5440 0.2 perl -Mblib
loop-timer-memleak.pl
It also slows down quite a bit towards the end; the print interval gets
a lot slower.
--
Paul Evans