in reply to perl memory re-usage

The two articles are talking about different things. The FAQ entry on shrinking the program talks about giving back memory to the operating system, which basically doesn't happen, or rather, depends on the OS and the memory allocation strategy built into Perl. The second entry talks about internal reuse of the memory allocated from the OS.

So, both are true, the memory gets reused by Perl but not (necessarily) given back to other programs.

Replies are listed 'Best First'.
Re^2: perl memory re-usage
by perrin (Chancellor) on Aug 08, 2006 at 21:15 UTC
    As I understand it, Perl will not reuse memory allocated for one lexical on another lexical, which means the second one is not really correct.
      Not always true:
      #!/usr/bin/perl use warnings; use strict; print "Press enter to start\n"; my $dummy = <>; { my $a = []; my $i = 10000000; push @$a,$i while ($i--); print "Allocated first array - Press enter to let it go out of sco +pe\n"; $dummy = <>; } print "Done. Press enter to continue with new array\n"; $dummy = <>; { my $a = []; my $i = 10000000; push @$a,$i while ($i--); } print "Done, press enter to exit\n"; $dummy = <>;
      Running this on linux with perl 5.8.8 / usemyalloc=n will reuse (most of) the memory used by the first @$a array. You can also see it free some of it to the OS if you watch top.

      Update: as far as I know, this only works for data referenced by lexicals - there are other ways to free memory used by arrays (i.e. setting $#array)