in reply to Re: out of memory problem
in thread out of memory problem
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: out of memory problem
by betterworld (Curate) on Sep 13, 2008 at 14:16 UTC | |
by ikegami (Patriarch) on Sep 13, 2008 at 15:56 UTC | |
by betterworld (Curate) on Sep 13, 2008 at 20:44 UTC | |
by ikegami (Patriarch) on Sep 13, 2008 at 21:26 UTC | |
by BrowserUk (Patriarch) on Sep 13, 2008 at 21:37 UTC |