Define 'give back'... I can't speak to Windows, but for every flavor of *nix I have ever used:
  1. make it re-usable by the current process. There are many situations where perl does this
  2. actually return memory to the OS. This is, in general, not possible. In *nix, once a process is allocated pages, there is no mechanism for giving them back. The only exception to this is memory added via mmap. If you munmap a file, and you are the only process that had it mapped, then this memory is returned to the OS. mmap, however, is typically only used for very specific things, like shared-lib access
  3. 'Kind of give it back'. If the memory you are no longer using spans pages, and you have a lot of memory in use, then the system will swap those pages out. They are still considered used by the OS, but they will never actually be put back into RAM. In most situations, this will not occur, because almost nobody wants to run a system that actually has to swap, since it usually comes with a significant performance hit.
update There are definitely situations where malloc does indeed make use of mmap instead of sbrk to obtain memory from the OS, for Linux and BSD. I believe that this is limited to single large allocations (>1MB by default), where there is not already that much contiguous free within the heap.

In reply to Re: demonstrate that perl can give back memory to the OS by Illuminatus
in thread demonstrate that perl can give back memory to the OS by perl5ever

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.