Note that because you don't use "my" here, all these variables will stay in memory even after the loop has finished.
That happens when using my too. Neither the SV nor the string buffer are freed. They are simply cleared.
Update: The following isn't proof, but it does let you see the effect of what I described.
use Devel::Peek qw( Dump ); sub foo { my ($x) = @_; undef($x) if !@_; Dump($x); } foo("abc"); foo("defghijkl"); foo("mno"); foo(undef); # $x = undef foo(); # undef $x foo("pqr");
Pay particular attention to LEN, the allocated length of the string buffer associated with the variable.
SV = PV(0x22612c) at 0x22606c REFCNT = 1 FLAGS = (PADBUSY,PADMY,POK,pPOK) PV = 0x22f4d4 "abc"\0 CUR = 3 LEN = 4 SV = PV(0x22612c) at 0x22606c Could be coincidence, but isn't. REFCNT = 1 The SV wasn't freed. FLAGS = (PADBUSY,PADMY,POK,pPOK) PV = 0x182cadc "defghijkl"\0 New larger (LEN=12) str buf. CUR = 9 LEN = 12 SV = PV(0x22612c) at 0x22606c REFCNT = 1 FLAGS = (PADBUSY,PADMY,POK,pPOK) PV = 0x182cadc "mno"\0 Same "large" (LEN=12) buf reused. CUR = 3 LEN = 12 SV = PV(0x22612c) at 0x22606c REFCNT = 1 FLAGS = (PADBUSY,PADMY) Undefined PV = 0x182cadc "mno"\0 Str buf untouched. CUR = 3 LEN = 12 SV = PV(0x22612c) at 0x22606c REFCNT = 1 FLAGS = (PADBUSY,PADMY) Undefined PV = 0 Str buf freed. SV = PV(0x22612c) at 0x22606c REFCNT = 1 FLAGS = (PADBUSY,PADMY,POK,pPOK) PV = 0x22f4d4 "pqr"\0 New small (LEN=4) str buf. CUR = 3 Same address as earlier LEN = 4 is a coincidence.
In reply to Re^2: out of memory problem
by ikegami
in thread out of memory problem
by lightoverhead
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |