in reply to demonstrate that perl can give back memory to the OS

Simple example:
sub ps { system("/bin/ps", "-o", "pid,size,vsize", $$); } ps(); { my $x = " " x 2_000_000; ps(); undef $x; } ps();
This is perl, v5.10.0 built for i686-linux-thread-multi

Replies are listed 'Best First'.
Re^2: demonstrate that perl can give back memory to the OS
by ikegami (Patriarch) on Feb 27, 2009 at 17:30 UTC

    An explanation:

    Lexical (my) variables and their string (or array) buffers aren't deallocated on scope exit whenever possible, only cleared. undef $var; (but not $var = undef;) deallocates the variable's string buffer.