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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |