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
$ perl -MDevel::Peek -e " my $a = q!1234!; Dump $a; " SV = PV(0x3e6964) at 0x3e8b54 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x98f664 "1234"\0 CUR = 4 LEN = 8 $ perl -MDevel::Peek -e " my $a = q!1234!; substr$a,0,2,q!!; Dump $a; +" SV = PVIV(0x98005c) at 0x3e8c04 REFCNT = 1 FLAGS = (PADMY,POK,OOK,pPOK) IV = 2 (OFFSET) PV = 0x98f746 ( "12" . ) "34"\0 CUR = 2 LEN = 6 $ perl -MDevel::Peek -e " my $a = q!1234!; substr($a,0,2)=q!!; Dump $a +; " SV = PVIV(0x98005c) at 0x3e8c0c REFCNT = 2 FLAGS = (PADMY,POK,OOK,pPOK) IV = 2 (OFFSET) PV = 0x98f746 ( "12" . ) "34"\0 CUR = 2 LEN = 6 $ perl -MDevel::Peek -e " my $a = q!1234!; substr($a,0,2)=q!!; substr$ +a,0,2,q!!; Dump $a; " SV = PVIV(0x98005c) at 0x3e8c1c REFCNT = 2 FLAGS = (PADMY,POK,OOK,pPOK) IV = 4 (OFFSET) PV = 0x98f778 ( "1234" . ) ""\0 CUR = 0 LEN = 4 $ perl -MDevel::Peek -e " my $a = q!1234!; substr$a,0,2,q!!; substr($a +,0,2)=q!!; Dump $a; " SV = PVIV(0x98005c) at 0x3e8c1c REFCNT = 2 FLAGS = (PADMY,POK,OOK,pPOK) IV = 4 (OFFSET) PV = 0x98f778 ( "1234" . ) ""\0 CUR = 0 LEN = 4
5.12.2
$ perl -MDevel::Peek -e " my $a = q!1234!; Dump $a; " SV = PV(0x3f6d74) at 0x9ba724 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x9bf9fc "1234"\0 CUR = 4 LEN = 8 $ perl -MDevel::Peek -e " my $a = q!1234!; substr$a,0,2,q!!; Dump $a; +" SV = PV(0x3f6d8c) at 0x9ba764 REFCNT = 1 FLAGS = (PADMY,POK,OOK,pPOK) OFFSET = 2 PV = 0x9bfa4e ( "1\002" . ) "34"\0 CUR = 2 LEN = 6 $ perl -MDevel::Peek -e " my $a = q!1234!; substr($a,0,2)=q!!; Dump $a +; " SV = PV(0x3f6d8c) at 0x9ba764 REFCNT = 2 FLAGS = (PADMY,POK,OOK,pPOK) OFFSET = 2 PV = 0x9bfa4e ( "1\002" . ) "34"\0 CUR = 2 LEN = 6 $ perl -MDevel::Peek -e " my $a = q!1234!; substr($a,0,2)=q!!; substr$ +a,0,2,q!!; Dump $a; " SV = PV(0x3f6d8c) at 0x9ba77c REFCNT = 2 FLAGS = (PADMY,POK,OOK,pPOK) OFFSET = 4 PV = 0x9bfa58 ( "1\0023\4" . ) ""\0 CUR = 0 LEN = 4 $ perl -MDevel::Peek -e " my $a = q!1234!; substr$a,0,2,q!!; substr($a +,0,2)=q!!; Dump $a; " SV = PV(0x3f6d8c) at 0x9ba77c REFCNT = 2 FLAGS = (PADMY,POK,OOK,pPOK) OFFSET = 4 PV = 0x9bfa58 ( "1\0023\4" . ) ""\0 CUR = 0 LEN = 4
my observations match those of the bug reports, each lvalue increases the refcount but there is no actual memory leak
in two runs of 441855/295946 iterations , memory remained constant at 2208k physical/ 524k virtual.
perl -e"my $c = 0; while(1){print qq!\r!,$c++; my $a = q!1234!; subst +r($a,0,2)=q!! for 1 .. rand(100); } "

In reply to Re^2: is this a memory leak or do I miss something? by Anonymous Monk
in thread is this a memory leak or do I miss something? by andal

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.