[Dbix-class] Memory leak when connect string has utf8 flag set

Roman Daniel roman.daniel at davosro.cz
Sun Feb 16 00:31:51 GMT 2014


Tracing some memory leak I found that my DBIC code leaks when the
connection string is utf8 flagged.

I tried to isolate it and now it seems to me that (only when connection
string (DSN) is utf8 flagged) after touching the database via DBIx::Class
any access to accessor defined via
Class::Accessor::Grouped::mk_group_accessors('inherited', ...) leaks
memory. The accessor can be from DBIx::Class
($schema->source_registrations) but also in other code.

The output for code below with $UTF8 = 1 is

    time    vsz (  diff)    rss (  diff) shared (  diff)   code (  diff)
data (  diff)
     0  68188 ( 68188)  19252 ( 19252)   2868 (  2868)   1368 (  1368)
 16532 ( 16532) before
    12  443200 ( 375012)  394132 ( 374880)   2876 (     8)   1368 (     0)
 391544 ( 375012) after

while the same code for $UTF8 = 0 shows completely different memory usage

  time    vsz (  diff)    rss (  diff) shared (  diff)   code (  diff)
data (  diff)
     0  68196 ( 68196)  19032 ( 19032)   2848 (  2848)   1368 (  1368)
 16540 ( 16540) before
    10  68196 (     0)  19032 (     0)   2848 (     0)   1368 (     0)
 16540 (     0) after

I use Perl v5.16.3 built for x86_64-linux and DBIx::Class version  0.08270

I know It sounds weird. Am I missing something?

Roman Daniel

use strict;
use warnings;
use DBIx::Class::Schema;
use File::Temp;
use DBI;
use Encode;
use Memory::Usage;

my $ITER = 8000000;
my $UTF8 = 1;

{
    package MySchema::Result::Artist;
    use base qw/DBIx::Class::Core/;

    __PACKAGE__->table('artist');
    __PACKAGE__->add_columns(qw/ artistid/);
    __PACKAGE__->set_primary_key('artistid');
}

# database
my $temp = File::Temp->new;
my $DBFILE = $temp->filename;
my $DSN = "dbi:SQLite:dbname=". $temp->filename;

DBI->connect($DSN)->do('create table artist (artistid number not null)');

my $schema = DBIx::Class::Schema->connect($UTF8?
Encode::decode('utf-8',$DSN): $DSN, '', '');
$schema->register_class('Artist', 'MySchema::Result::Artist');
$schema->resultset('Artist')->find(0);

my $mu = Memory::Usage->new;
$mu->record('before');
for(my $i = 0; $i < $ITER; $i++){
        $schema->source_registrations;
}
$mu->record('after');
$mu->dump;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20140216/594042a1/attachment.htm>


More information about the DBIx-Class mailing list