Subject: | __ACTIONn__ key in parse tree seems to cause a memory leak |
The __ACTIONn__ key in the output parse tree seems to create a circular reference and subsequently causes a memory leak.
use Parse::RecDescent;
use Data::Dumper;
use Test::Memory::Cycle;
my $grammar = q(
startrule :
day month date
day :
"Sat" | "Sun" | "Mon" | "Tue" | "Wed" | "Thu" | "Fri"
month :
"Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" |
"Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
date:
/\d+/
{
$item{'INT'} = bless( {'__VALUE__' => $item[1]}, 'INT' );
bless \%item, $item[0];
}
);
my $parser = Parse::RecDescent->new($grammar);
my $tree = $parser->startrule("Sun Mar 31");
print Dumper($tree);
memory_cycle_ok($tree);
The result is:
$VAR1 = bless( {
'__RULE__' => 'date',
'__ACTION1__' => $VAR1,
'DATE' => $VAR1,
'INT' => bless( {
'__VALUE__' => '31'
}, 'INT' ),
'__PATTERN1__' => '31'
}, 'date' );
not ok 1
# Failed test at ... line 22.
# Cycle #1
# date A->{__ACTION1__} => date A
# Tests were run but no plan was declared and done_testing() was not seen.