oliwer / mango

Pure-Perl non-blocking I/O MongoDB driver
https://metacpan.org/release/Mango
Artistic License 2.0
27 stars 12 forks source link

why memory leak ? #4

Closed electricface closed 9 years ago

electricface commented 9 years ago
#!/usr/bin/env perl
use 5.018;
use warnings;
use utf8;

use Mango;
use Mango::BSON qw(:bson);
use Mojo::IOLoop;
my $mango = Mango->new;
my $db = $mango->db('test');
my $col = $db->collection('col');

Mojo::IOLoop->recurring(0, sub {
    $col->insert({createAt => bson_time}, sub {
        warn "done 1";
        $col->update({_id => ""}, {createAt => bson_time }, sub {
            warn "done 2";
        });
    });
});

Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
oliwer commented 9 years ago

Hello,

What your program does is to continually add callbacks to the ioloop, without letting time to the ioloop to execute them. So they get stock-piled and eat your memory. Subroutines consume memory just like any other variable.

Note that you will obtain the same result with any other module that uses Mojo::IOLoop.

What is the real problem behind this? Do you receive events faster than you can store them in MongoDB?