Hello, fellow monks!

Imagine this:

my @arr = (9) x 1000_000; my $code = sub { @arr }; undef $code;

The sub will create a local copy of @arr as it's really a closure not a simple sub. And as soon as the ref to the sub vanishes we lose ability to address that copy. Will it be garbage-collected? Anonymous subs cannot be GCed as far as I understand, the code is there forever, and what about the scratchpad (I may misuse the term) for copies of lexical vars?

Are there ways to creatively employ Devel::Size, Devel::Peek, B::LexInfo or some other module to get information on all currently allocated objects? The ps(1) is rather useless in this case because perl process may not return (on some systems it even cannot) the memory to the OS as soon as it's freed.

--kap

In reply to Lost anonymous subs by kappa

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.