<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(&#39;inherited&#39;, ...) leaks memory. The accessor can be from DBIx::Class ($schema-&gt;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__-&gt;table(&#39;artist&#39;);</div><div>    __PACKAGE__-&gt;add_columns(qw/ artistid/);</div>
<div>    __PACKAGE__-&gt;set_primary_key(&#39;artistid&#39;);</div><div>}</div><div><br></div><div># database</div><div>my $temp = File::Temp-&gt;new;</div><div>my $DBFILE = $temp-&gt;filename;</div><div>my $DSN = &quot;dbi:SQLite:dbname=&quot;. $temp-&gt;filename;</div>
<div><br></div><div>DBI-&gt;connect($DSN)-&gt;do(&#39;create table artist (artistid number not null)&#39;);</div><div><br></div><div>my $schema = DBIx::Class::Schema-&gt;connect($UTF8? Encode::decode(&#39;utf-8&#39;,$DSN): $DSN, &#39;&#39;, &#39;&#39;);</div>
<div>$schema-&gt;register_class(&#39;Artist&#39;, &#39;MySchema::Result::Artist&#39;);</div><div>$schema-&gt;resultset(&#39;Artist&#39;)-&gt;find(0);</div><div><br></div><div>my $mu = Memory::Usage-&gt;new;</div><div>$mu-&gt;record(&#39;before&#39;);</div>
<div>for(my $i = 0; $i &lt; $ITER; $i++){</div><div>        $schema-&gt;source_registrations;</div><div>}</div><div>$mu-&gt;record(&#39;after&#39;);</div><div>$mu-&gt;dump;</div></div><div><br></div></div>