I believe that in those examples, Perl is actually leaking the scalars, along with a lot of other stuff -- look at the "still reachable" stat. It's doing this intentionally, by exiting immediately rather than painstakingly deallocating everything first.

In order to persuade Perl to deallocate everything, you need a Perl compiled with -DDEBUGGING and to set the PERL_DESTRUCT_LEVEL environment variable to 2. You are also likely need to create a Valgrind suppressions file to adapt for miscellaneous noise from libc, Dynaloader, etc.

In the end, though, you still don't see any difference when running those two examples. I would argue that the proof needed tightening up -- but the reasoning and explanation were sound.
marvin@smokey:~ $ PERL_DESTRUCT_LEVEL=2 valgrind --show-reachable=yes +--leak-check=full \ > --suppressions=~/debugperl.supp \ > debugperl -e'my $x; $x = \$x; undef $x if $ARGV[0]' 1 ==79872== Memcheck, a memory error detector ==79872== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et +al. ==79872== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright + info ==79872== Command: debugperl -emy\ $x;\ $x\ =\ \\$x;\ undef\ $x\ if\ $ +ARGV[0] 1 ==79872== --79872-- /Users/marvin/bin/debugperl: --79872-- dSYM directory has wrong UUID; consider using --dsymutil=yes ==79872== ==79872== HEAP SUMMARY: ==79872== in use at exit: 94,131 bytes in 12 blocks ==79872== total heap usage: 625 allocs, 613 frees, 219,612 bytes all +ocated ==79872== ==79872== LEAK SUMMARY: ==79872== definitely lost: 0 bytes in 0 blocks ==79872== indirectly lost: 0 bytes in 0 blocks ==79872== possibly lost: 0 bytes in 0 blocks ==79872== still reachable: 0 bytes in 0 blocks ==79872== suppressed: 94,131 bytes in 12 blocks ==79872== ==79872== For counts of detected and suppressed errors, rerun with: -v ==79872== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from +0) marvin@smokey:~ $ PERL_DESTRUCT_LEVEL=2 valgrind --show-reachable=yes +--leak-check=full \ > --suppressions=~/debugperl.supp \ > debugperl -e'my $x; $x = \$x; undef $x if $ARGV[0]' 0 ==79881== Memcheck, a memory error detector ==79881== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et +al. ==79881== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright + info ==79881== Command: debugperl -emy\ $x;\ $x\ =\ \\$x;\ undef\ $x\ if\ $ +ARGV[0] 0 ==79881== --79881-- /Users/marvin/bin/debugperl: --79881-- dSYM directory has wrong UUID; consider using --dsymutil=yes ==79881== ==79881== HEAP SUMMARY: ==79881== in use at exit: 94,131 bytes in 12 blocks ==79881== total heap usage: 625 allocs, 613 frees, 219,612 bytes all +ocated ==79881== ==79881== LEAK SUMMARY: ==79881== definitely lost: 0 bytes in 0 blocks ==79881== indirectly lost: 0 bytes in 0 blocks ==79881== possibly lost: 0 bytes in 0 blocks ==79881== still reachable: 0 bytes in 0 blocks ==79881== suppressed: 94,131 bytes in 12 blocks ==79881== ==79881== For counts of detected and suppressed errors, rerun with: -v ==79881== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from +0) marvin@smokey:~ $

In reply to Re^4: Make Perl use real malloc by creamygoodness
in thread Make Perl use real malloc by creamygoodness

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.