Subject: | memory leak when daughter handler is used |
Hello.
I have noticed memory leak when daughter handler is used.
The code for reproducing is below.
$| = 1;
use strict;
use warnings;
use HTML::Parser;
my $html = join "\n", "<html>", (map { "<a href=\"$_\">$_</a>" } 1 .. 1000), "</html>";
sub parsing {
my ($html) = @_;
my $prs = HTML::Parser->new(api_version => 3);
# Memory leak
$prs->handler(start => sub {
$prs->handler(text => sub {});
$prs->handler(end => sub {
$prs->handler(text => undef);
$prs->handler(end => undef);
});
});
# # OK
# $prs->handler(start => sub {});
# $prs->handler(text => sub {});
# $prs->handler(end => sub {});
$prs->parse($html);
$prs->eof;
}
print `ps u $$`; # On FreeBSD `ps -u $$`
foreach my $i (1 .. 5) {
foreach (1 .. 1000) {
parsing($html);
}
print "$i\n";
print `ps u $$`;
}