I'm curious what your code looks like. While it doesn't surprise me if the OS fails to reclaim freed memory, I'm surprised that you're finding that after a variable goes out of scope its memory isn't in some way reused by Perl. Could you boil down a snippet that does what you're talking about?

Here is a test snippet where you can prove to yourself that Perl does re-use its own memory space. The following snippet maintains a continuous loop where 10,001 hash elements are assigned integer values, and then the hash falls from scope and is recreated again. If the same memory isn't reused by Perl, it should take no time at all for this snippet to fill all available memory. But as I watch Perl's memory usage in the Windows Task manager, it never jumps above about 4,300k, so my test doesn't reproduce your issue. At least in this case, Perl does the right thing.

use strict; use warnings; while (1) { my %hash; @hash{0..10000} = (0..10000); }

By the way, (this is completely unrelated to your question) this snippet does get me a little wierd error intermittantly upon termination with a CTRL-C break:

Terminating on signal SIGINT(2) Terminating on signal SIGINT(2) Attempt to free unreferenced scalar: SV 0x188d214 at C:\Perl\Scripts\m +ytest.pl line 9.

...line nine is the line with the hash slice on it. I'm using Active State Perl 5.8.2, binary build 808. The error occurred twice out of a few dozen repeated attempts. Of course this error is unrelated to your question, but curious nevertheless.


Dave


In reply to Re: Uncollected garbage leads to swapping ... by davido
in thread Uncollected garbage leads to swapping ... 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.