I was looking through lists of "memorable nodes", collected on some monks' home pages, that's why I came here to such old discussion.

I can't quite agree:

It's not: "how memory management is in Perl"; it's: how memory management is!

In general, it is expensive for a process to request more memory from the OS; so once a process (via your C compiler memory management functions) have requested memory from the OS, they are reluctant to give it back

It looks like, memory requested by XS code is eventually returned to OS (right?). And memory, allocated in separate threads, upon their completion, is returned, too. (That's why if I want long-running program to have sane memory-footprint, I'd place memory hungry code in a thread. Or even, cf. my last question about child processes and IPC, to separate it completely.)

But, "pure Perl" mono-thread is, indeed, reluctant to give anything back.

Here's on Win32 5.020 (your numbers may vary, and sorry for a bit barbaric "memory monitoring code". CPAN Windows-compatible modules seem to fail with threads):

use strict; use warnings; use threads; use PDL; PDL::no_clone_skip_warning; sub mem { qx{ typeperf "\\Process(perl)\\Working Set" -sc 1 } =~ /(\d+)\.\d+\"$/m; ( my $s = $1 ) =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g; printf "%-30s: %12s\n", @_, $s } mem 'initially'; my $p = zeroes 50_000_000; mem 'we\'ve made a huge piddle!'; undef $p; mem 'and now it\'s gone'; sub test_arr { my @a = 1 .. ${ \10_000_000 }; mem 'we\'ve made a huge array!'; @a = undef; mem 'and now it\'s gone'; } async( \&test_arr )-> join; mem 'and now a thread is gone, too'; print "\nbut let\'s try it in main thread!\n\n"; test_arr; mem 'finally';

The output:

initially : 16,846,848 we've made a huge piddle! : 418,107,392 and now it's gone : 17,321,984 we've made a huge array! : 628,912,128 and now it's gone : 628,928,512 and now a thread is gone, too : 20,258,816 but let's try it in main thread! we've made a huge array! : 625,430,528 and now it's gone : 625,430,528 finally : 625,430,528

In reply to Re^8: ithreads memory leak by vr
in thread ithreads memory leak by DNAb

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.