in reply to is this a memory leak or do I miss something?

What happens when you use a four argument substr?

substr $a, 0, 2, '';

Replies are listed 'Best First'.
Re^2: is this a memory leak or do I miss something?
by Anonymous Monk on Oct 28, 2010 at 10:21 UTC
    perl -MDevel::Peek -e " my $a = q!1234!; Dump $a; " perl -MDevel::Peek -e " my $a = q!1234!; substr$a,0,2,q!!; Dump $a; " perl -MDevel::Peek -e " my $a = q!1234!; substr($a,0,2)=q!!; Dump $a; +" perl -MDevel::Peek -e " my $a = q!1234!; substr($a,0,2)=q!!; substr$a, +0,2,q!!; Dump $a; " perl -MDevel::Peek -e " my $a = q!1234!; substr$a,0,2,q!!; substr($a,0 +,2)=q!!; Dump $a; "
    on 5.10.0 / 5.8.9 5.12.2 my observations match those of the bug reports, each lvalue increases the refcount but there is no actual memory leak
      Yep. I also don't see any memory leak. I guess, that this extra locking is essential for the work of functions as lvalue. pos and vec cause the same behaviour. The variable is locked as many times as there are usages of function as lvalue. Then it is not a bug, but just a feature.
Re^2: is this a memory leak or do I miss something?
by XooR (Beadle) on Oct 28, 2010 at 09:57 UTC

    On my machine, then I get refcount 1

    SV = PVIV(0x81f14ec) at 0x81fb5a8 REFCNT = 1 FLAGS = (PADMY,POK,OOK,pPOK) IV = 2 (OFFSET) PV = 0x81f5e22 ( "te" . ) "st"\0 CUR = 2 LEN = 6
    Machine:
    This is perl, v5.10.1 (*) built for i686-linux-gnu-thread-multi
    (with 40 registered patches, see perl -V for more detail)