Hi Monks, I know this theme 50069 was discussed in 2001, but does anybody has deep information on how to influence the garbage collector, to free memory (in the sense of give it back to the OS)? Let me show:
{ my $foo = 'X' x 100000000; getc; } undef $foo; my $foo = ""; getc;
At the first prompt (via ps auxwf output):
user 12310 2.1 4.8 211000 197024 pts/2 At the second prompt: user 12310 1.2 4.8 211000 197028 pts/2
Now, what I wanted to show: - the memory allocated for $foo is not released. What I read on several mailing-lists is that the optimizer does not return the memory to the OS, in the hope that the same variable will be used again. But what I'm missing is some kind of a 'free' statement in Perl, which definitely returns memory (and I not know yet, undef seems not to help).
Let me show another example:
$foo = 'X' x 100000000; getc; undef $foo; getc; $foo2 = 'X' x 100000000; getc;
gives (again output from 'ps auxwf'):
user 15185 18.0 4.8 211000 197020 pts/5 user 15185 5.0 2.4 113340 99364 pts/5 user 15185 4.3 7.2 308660 294684 pts/5
As you see some RAM is given back to the OS (~50%, (99364/197020)) . BUT: I would expect that the Perl virtual machine (memory management) reuses the allocated RAM from $foo for $foo2.
As you see $foo is not used anymore in the program context, but the memory management still holds some RAM for it present (I mean why ?).
(I'm using perl 5.10.0 on OpenSUSE 11.0)

In reply to 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.