Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marpa::R2 leaks memory

I am using latest release of marpa::r2 (Marpa-R2-2.065_002) and it seems to eat all memory very fast. I wrote the bellow script to test it.

use strict;
use warnings FATAL => 'all';
use Marpa::R2;
use Data::Dumper;

my $grammar = Marpa::R2::Scanless::G->new({
 action_object => __PACKAGE__,
 source => \(<<'END_OF_SOURCE'),
 :default ::= action => ::array
 :start ::= path
 path ::=
  step               action => _do_step
 step ~ [a-z]+ 
END_OF_SOURCE
});

sub _do_step{ return {step => $_[1]}};


sub new {}     #The Marpa::R2 needs it
sub compile{
 my ($query) = @_; 
 return undef unless $query;

 my $reader = Marpa::R2::Scanless::R->new({
  grammar => $grammar,
  trace_terminals => 0,
 });
 $reader->read(\$query);
 print Dumper $reader->value;
}

compile($_) foreach ('aaaa'..'zzzz'); 

What can I do to prevent the memory leaks?

Edit: This is now reported as a bug to rt.cpan.

Edit: It is now fixed on release Marpa-R2 2.066000. Thanks

like image 547
jvverde Avatar asked Jul 28 '13 20:07

jvverde


1 Answers

The leak is fixed in Marpa-R2 2.065_006 on CPAN. Thanks for pointing this out and thanks to amon for the minimal example, which saved me time and made things easier.

The problem turned out to be in the Perl code. Two structures held references to each other -- a circular reference. Testing the fixed version with amon's example produces memory use that is absolutely flat over time.

I'll get this fix into an indexed (that is non-developer's) release on CPAN as soon as possible.

like image 158
Jeffrey Kegler Avatar answered Nov 08 '22 03:11

Jeffrey Kegler