Since @List is scoped within Process, it will be destroyed when Process exits (unless you do something with the "return value" of Process, which will be the right-hand-side of your last assignment: a single FormData item), which will destroy every element of the array in the process. Perl keeps its own reference count of each variable, even if it's nested within another. When FormData exits, $UserData is destroyed, but the data it was pointing to gets allocated into a @List element, so the reference count goes from 1 to 2 to 1 (or maybe just 1 -> 1; I'm no expert). When your first function terminates, @List is destroyed, dropping the reference counts for each of its elements to 0, causing them to be reaped in turn as well.

Remember that resources aren't literally free()'d, they're just returned to the pool for other Perl variables to use as needed. You cannot "release" memory consumed by now-unused variables back to the OS. See How can I free an array or hash so my program shrinks?.


In reply to Re: Garbage Collection by Fastolfe
in thread Garbage Collection by Anonymous Monk

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.