<div dir="ltr">Tracing some memory leak I found that my DBIC code leaks when the connection string is utf8 flagged. <div><br></div><div>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.</div>
<div><br></div><div>The output for code below with $UTF8 = 1 is </div><div><br></div><div><div> time vsz ( diff) rss ( diff) shared ( diff) code ( diff) data ( diff)</div><div> 0 68188 ( 68188) 19252 ( 19252) 2868 ( 2868) 1368 ( 1368) 16532 ( 16532) before</div>
<div> 12 443200 ( 375012) 394132 ( 374880) 2876 ( 8) 1368 ( 0) 391544 ( 375012) after</div><div><br></div><div>while the same code for $UTF8 = 0 shows completely different memory usage</div><div> <br></div>
<div> time vsz ( diff) rss ( diff) shared ( diff) code ( diff) data ( diff)<br></div><div> 0 68196 ( 68196) 19032 ( 19032) 2848 ( 2848) 1368 ( 1368) 16540 ( 16540) before</div><div> 10 68196 ( 0) 19032 ( 0) 2848 ( 0) 1368 ( 0) 16540 ( 0) after</div>
</div><div><br></div><div>I use Perl v5.16.3 built for x86_64-linux and DBIx::Class version 0.08270<br></div><div><br></div><div>I know It sounds weird. Am I missing something? </div><div><br></div><div>Roman Daniel</div>
<div><br></div><div><div>use strict;</div><div>use warnings;</div><div>use DBIx::Class::Schema;</div><div>use File::Temp;</div><div>use DBI;</div><div>use Encode;</div><div>use Memory::Usage;</div><div><br></div><div>my $ITER = 8000000;</div>
<div>my $UTF8 = 1;</div><div><br></div><div>{</div><div> package MySchema::Result::Artist;</div><div> use base qw/DBIx::Class::Core/;</div><div><br></div><div> __PACKAGE__->table('artist');</div><div> __PACKAGE__->add_columns(qw/ artistid/);</div>
<div> __PACKAGE__->set_primary_key('artistid');</div><div>}</div><div><br></div><div># database</div><div>my $temp = File::Temp->new;</div><div>my $DBFILE = $temp->filename;</div><div>my $DSN = "dbi:SQLite:dbname=". $temp->filename;</div>
<div><br></div><div>DBI->connect($DSN)->do('create table artist (artistid number not null)');</div><div><br></div><div>my $schema = DBIx::Class::Schema->connect($UTF8? Encode::decode('utf-8',$DSN): $DSN, '', '');</div>
<div>$schema->register_class('Artist', 'MySchema::Result::Artist');</div><div>$schema->resultset('Artist')->find(0);</div><div><br></div><div>my $mu = Memory::Usage->new;</div><div>$mu->record('before');</div>
<div>for(my $i = 0; $i < $ITER; $i++){</div><div> $schema->source_registrations;</div><div>}</div><div>$mu->record('after');</div><div>$mu->dump;</div></div><div><br></div></div>