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

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); } "

Replies are listed 'Best First'.
Re^3: is this a memory leak or do I miss something?
by andal (Hermit) on Oct 28, 2010 at 11:15 UTC
    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.