[librecat-dev] Catmandu(?) eating memory

Michael Kapp limodev at yulux.de
Wed Mar 9 12:17:54 CET 2016


Hi,

the below script eating all memory.

Every two seconds it creates a hash (with test data) and put's it into a 
catmandu sqlite db:

my $test_dat = { map { rand($_) => 1 } 1 .. 1000 };
my $sqlite = Cat::DB->new(data => $test_dat);
$sqlite->create;

If I comment the line:

$self->env->add($self->data); ## eating memory

The possible memory leak stops.

I don't know what I'm doing wrong.

Are there any hints to prevent this?

thx & regards,
Michael

---------------------------------

package Cat::DB;
use Mouse;
use Catmandu::Store::DBI;
use namespace::autoclean;

has 'data' => (
   traits    => ['Hash'],
   is        => 'rw',
   required  => 1,
   isa       => 'HashRef',
   default   => sub { {} },
);

sub env {
   my $self = shift;
   my $cstore = Catmandu::Store::DBI->new(
         data_source => 'DBI:SQLite:database=/tmp/test.db',
         bags => {
           test => {
             autocommit => 1,
             plugins => [ 'Datestamps' ]
           }
         }
       );
   return $cstore->bag('test');
};

sub create {
   my $self = shift;
   eval {
     $self->env->add($self->data); ## eating memory
   };
   if (my $e = $@) {
       print("Something went wrong: $e\n");
       return;
   }
};

no Mouse;
__PACKAGE__->meta->make_immutable;
1;

package main;
use strict;
use warnings;

my $start_time = time();
my $wait_time = 2;
my $never_happen = 0;
my $seconds = 0;

do {
     if (((time() - $start_time) % $wait_time) == 0) {
         &create_data;
     }
} until ($never_happen);


sub create_data {
     print "Seconds elapsed: $seconds\n";
     my $test_dat = { map { rand($_) => 1 } 1 .. 1000 };
     my $sqlite = Cat::DB->new(data => $test_dat);
     $sqlite->create;
     sleep(1); # to stop multiple instances
     $seconds += $wait_time;
}




More information about the librecat-dev mailing list