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


In reply to Re: memory "release" with $#=-1 by tlm
in thread memory "release" with $#=-1 by ISAI student

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.