After some play with Perl (5.8.8 and 5.10.0) I finally have some results:
diff -urN perl-5.8.8/scope.c perl-5.8.8_/scope.c --- perl-5.8.8/scope.c 2005-09-30 15:56:51.000000000 +0200 +++ perl-5.8.8_/scope.c 2009-02-23 16:23:40.000000000 +0100 @@ -946,14 +946,26 @@ SvREFCNT_dec(AvARYLEN(sv)); AvARYLEN(sv) = 0; } + av_undef((AV*)sv); break; case SVt_PVHV: hv_clear((HV*)sv); + hv_undef((HV*)sv); break; case SVt_PVCV: Perl_croak(aTHX_ "panic: leave_scope pad code"); default: SvOK_off(sv); + const U32 padflags + = SvFLAGS(sv) & (SVs_PADBUSY|SVs_PADMY|SVs_PADTMP); + switch (SvTYPE(sv)) { /* Console ourselves with a ne +w value */ + case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break; + case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break; + default: *(SV**)ptr = NEWSV(0,0); break; + } + SvREFCNT_dec(sv); /* Cast current value to the w +inds. */ + SvFLAGS(*(SV**)ptr) |= padflags; /* preserve pad natur +e */ + break; } }
So yes, I have patched the file scope.c. Because a lot of the (existing) code does not use a explicit undef on a scope exit (of course, does this imply a variable declared with 'my').
At least it helps me to free some malloced space on a scope close (see below).
print "Start: >".$$."<\n";<>; { my @arr; $arr[$_]=$_ foreach(1 .. 1000000); print "How Many?\n";<>; #->not needed: undef @arr; } print "Done, how many?\n";<>;

In reply to Re: Perl Garbage Collection, again by pkirsch
in thread Perl Garbage Collection, again by pkirsch

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.