in reply to out of memory problem after undef

I can't say how it would work on win32, but on linux, I've had luck with Perl releasing huge memory back to the system, if the array was in a thread, and the thread was joined/finished.
#!/usr/bin/perl use threads; use threads::shared; use warnings; use strict; print $$,"\n"; # top -p $$ to check my $alive:shared = 0; my $thr = threads->create(\&display); print "check mem use, then hit any key\n"; <>; #check mem use $alive = 1; $thr->join; print "check mem use, then hit any key\n"; <>; #check mem use $alive = 0; my $thr1 = threads->create(\&display); print "check mem use, then hit any key\n"; <>; #check mem use $alive = 1; $thr1->join; print "check mem use, then hit any key to finally exit\n"; <>; #check mem use sub display { my @array; foreach (1..10000000){ push @array, 'aaaa'; } while(1){ last if $alive; sleep 1; } undef @array; return; }

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: out of memory problem after undef
by ikegami (Patriarch) on Dec 03, 2008 at 20:35 UTC

    I can't say how it would work on win32, but on linux, I've had luck with Perl releasing huge memory back to the system

    Win32 does release back to the OS, but we're not talking about releasing back to the system. Releasing back to Perl is fine.