in reply to memory "release" with $#=-1
I don't know if this test is conclusive, but from the result of the following script, it looks like the answer to your question is "no":
use strict; use warnings; my @x = 1..10; print '@x is at ', \@x, "\n"; $#x = -1; my @y = 1..5; print '@y is at ', \@y, "\n"; print '@x is at ', \@x, "\n"; __END__ @x is at ARRAY(0x8165ccc) @y is at ARRAY(0x8183ab0) @x is at ARRAY(0x8165ccc)
Update: OK, so the script above is not conclusive, as ikegami points out (in fact, as it turns out, it leads to the wrong conclusion).
Devel::Peek is a better tool to answer this question. With the better information I must reject my earlier hypothesis: the answer is "yes" (i.e. space does get reused).
Note that memory location 0x811b400 originally occupied by $x[ 0 ], is occupied by $y[ 0 ] afterwards.
use strict; use warnings; use Devel::Peek; my @x = 1..3; print "Dump of \@x:\n"; Dump \@x; $#x = -1; my @y = 1; print "\nDump of \@y:\n"; Dump \@y; print "\nDump of \@x:\n"; Dump \@x; __END__ Dump of @x: SV = RV(0x8138618) at 0x811b574 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x8128d68 SV = PVAV(0x811c904) at 0x8128d68 REFCNT = 2 FLAGS = (PADBUSY,PADMY) IV = 0 NV = 0 ARRAY = 0x8154d00 FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = IV(0x81286a8) at 0x811b400 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 Elt No. 1 SV = IV(0x81286ac) at 0x811b4b4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 2 Elt No. 2 SV = IV(0x81286a4) at 0x811b538 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 3 Dump of @y: SV = RV(0x8138618) at 0x811b4b4 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x8144dc8 SV = PVAV(0x811c95c) at 0x8144dc8 REFCNT = 2 FLAGS = (PADBUSY,PADMY) IV = 0 NV = 0 ARRAY = 0x814abd8 FILL = 0 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = IV(0x81286a8) at 0x811b400 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 Dump of @x: SV = RV(0x8138618) at 0x811b4b4 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x8128d68 SV = PVAV(0x811c904) at 0x8128d68 REFCNT = 2 FLAGS = (PADBUSY,PADMY) IV = 0 NV = 0 ARRAY = 0x8154d00 FILL = -1 MAX = 3 ARYLEN = 0x811b574 FLAGS = (REAL)
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: memory "release" with $#=-1
by ikegami (Patriarch) on Jun 28, 2005 at 15:33 UTC |