Marpa::R2 leaks memory
Asked Answered
A

1

8

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

Amoral answered 28/7, 2013 at 20:48 Comment(4)
confirmed with my Marpa v2.064 on perl5 v16.3. Minimal code to reproduce: perl -MMarpa::R2 -e'*M:: = *Marpa::R2::Scanless::; my $g = M::G->new({source => \q(:start ::= A A ::= [ ])}); M::R->new({grammar => $g}) for 1 .. 1E5'. Have you already filed a bug?Plasterwork
Filed a bug? Sorry i am new on these things. Where should I do that? Thanks for you confirmation and minimal codeAmoral
Ok, bug reported to bug-Marpa-R2 [at] rt.cpan.orgAmoral
amon is right. I've received the bug report. I treat memory leaks as serious issues, and it will take a high priority.Branca
B
6

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.

Branca answered 31/7, 2013 at 15:37 Comment(2)
Yes, I already try it with my code and it works like a charm. Thank you!Amoral
This fix is now included in a full, indexed, CPAN distribution: Marpa-R2 2.066000Branca

© 2022 - 2024 — McMap. All rights reserved.