perl5ever has asked for the wisdom of the Perl Monks concerning the following question:

When I run this program:
use Devel::LeakTrace::Fast; { my $x = []; }
I get:
leaked SV(0x0x8e5ac28) from ./t0 line 5 leaked SV(0x0x8e5ae38) from ./t0 line 5
However, if I remove the curly braces I don't get any reports of leakage.

Am I really leaking memory? (This is with 5.8.8.)

Replies are listed 'Best First'.
Re: question about Devel::LeakTrace::Fast
by ikegami (Patriarch) on Apr 21, 2009 at 19:17 UTC
    $ perl -e'use Devel::LeakTrace::Fast; { my $x = []; }' leaked SV(0x0x814ec28) from -e line 1 leaked SV(0x0x814ed84) from -e line 1 $ perl -e'use Devel::LeakTrace::Fast; { my $x = []; 1; }' $ perl -e'use Devel::LeakTrace::Fast; { my $x = []; } 1;' $

    I suspect the value to which the sassign (=) evaluates (the reference returned by []) is on the stack for some unknown reason. As show, it doesn't stay there if you add *anything* to the program. So not a leak. For example, the only difference in the above "leaking" and fine code is an op used to give line numbers to warnings.

    $ diff -u \ > <( perl -MO=Concise,-exec -we'use Devel::LeakTrace::Fast; { my $x + = []; } ' 2>&1 ) \ > <( perl -MO=Concise,-exec -we'use Devel::LeakTrace::Fast; { my $x + = []; } 1' 2>&1 ) --- /dev/fd/63 2009-04-21 15:31:32.471371429 -0400 +++ /dev/fd/62 2009-04-21 15:31:32.475372857 -0400 @@ -9,4 +9,5 @@ 8 <0> padsv[$x:279,280] sRM*/LVINTRO 9 <2> sassign vKS/2 a <2> leaveloop vK/2 +b <;> nextstate(main 281 -e:1) v <-- only difference -b <@> leave[1 ref] vKP/REFC +c <@> leave[1 ref] vKP/REFC

    Oddly, I can't reproduce it using

    $ perl -e'use Devel::LeakTrace::Fast; { my $x = []; $x }' $

    The two values being "leaked", incidentally, must be the reference and the array being referenced.

      Devel::Leak doesn't show any leaks
      C:\>perl -MDevel::Leak -le"print Devel::Leak::NoteSV($handle); { my $x + = []; } print Devel::Leak::CheckSV($handle);" 5513 5513 C:\>perl -MO=Concise -e" { my $x = []; } a <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 3 -e:1) v ->3 9 <2> leaveloop vK/2 ->a 3 <{> enterloop(next->9 last->9 redo->4) v ->4 - <@> lineseq vK ->9 4 <;> nextstate(main 1 -e:1) v ->5 8 <2> sassign vKS/2 ->9 6 <@> anonlist sK* ->7 5 <0> pushmark s ->6 7 <0> padsv[$x:1,2] sRM*/LVINTRO ->8 -e syntax OK C:\>perl -MO=Concise -e" { my $x = []; 1} b <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 3 -e:1) v ->3 a <2> leaveloop vK/2 ->b 3 <{> enterloop(next->a last->a redo->4) v ->4 - <@> lineseq vKP ->a 4 <;> nextstate(main 1 -e:1) v ->5 8 <2> sassign vKS/2 ->9 6 <@> anonlist sK* ->7 5 <0> pushmark s ->6 7 <0> padsv[$x:1,2] sRM*/LVINTRO ->8 9 <;> nextstate(main 2 -e:1) v ->a - <0> ex-const v ->- -e syntax OK C:\>pmvers Devel::Leak 0.03 C:\>perl -v|grep buil This is perl, v5.8.9 built for MSWin32-x86-multi-thread Binary build 825 [288577] provided by ActiveState http://www.ActiveSta +te.com