Actually it depends on how you allocate memory and on malloc implementation. E.g. on linux malloc may use to allocate memory brk if you asking some small amount or mmap if you wanna much of it. Memory allocated by brk usually can't be freed, but mmaped memory may be easily munmaped. Here's example that demonstrates this:

use strict; use warnings; my $hr = {}; my ($num, $size) = @ARGV; print "$num, $size\n"; system("ps vp $$"); for (1..$num) { $hr->{$_} = 'memory' x $size; } system("ps vp $$"); undef $hr; system("ps vp $$");

On my Ubuntu amd64 I got the following results:

$ perl memory.pl 10000 1000 10000, 1000 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 14098 pts/0 S+ 0:00 0 3 18164 2292 0.0 perl memory.p +l 10000 1000 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 14098 pts/0 S+ 0:00 0 3 78204 62436 1.5 perl memory.p +l 10000 1000 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 14098 pts/0 R+ 0:00 0 3 77384 61648 1.5 perl memory.p +l 10000 1000 $ perl memory.pl 100 100000 100, 100000 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 14105 pts/0 S+ 0:00 0 3 18164 2292 0.0 perl memory.p +l 100 100000 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 14105 pts/0 S+ 0:00 0 3 77552 61684 1.5 perl memory.p +l 100 100000 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 14105 pts/0 R+ 0:00 0 3 18752 2888 0.0 perl memory.p +l 100 100000

If you check with strace you'll see that it uses brk in first case, but mmap/munmap in the second.


In reply to Re: Long running tasks, perl and garbage collection by zwon
in thread Long running tasks, perl and garbage collection by GoCool

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.