On Fri, 7 Sep 2001, Chris Fedde wrote:

> On Fri, 7 Sep 2001 16:58:32 -0400  Michael G Schwern wrote:
>  +------------------
>  | On Fri, Sep 07, 2001 at 02:32:51PM -0600, Chris Fedde wrote:
>  | > Find below recent patches to the FAQ derived from postings to usenet CLPM.
>  | > Is there a better place I should be posting these?
>  |
>  | > +If you need to initialize a large variable in your code, you
>  | > +might consider doing it with an C<eval> statement:
>  | > +
>  | > +        my $large_string = eval ' "a" x 5_000_000 ';
>  | > +
>  | > +This allows perl to immediately free the memory allocated to the
>  | > +eval statement, but carries a (small) performance penalty.
>  |
>  | Does this really work?
>  +------------------
>
> Apparently.
>
>     cat t
>         my $large_string = eval ' "a" x 5_000_000 ';
>         print "holding\n";
>
>     ps -axo pid,rsz,vsz,tsiz,command | grep perl
>         47904 3692  4188  656 perl -d t
>
>     cat u
>         my $large_string = "a" x 5_000_000;
>         print "holding\n";
>
>     ps -axo pid,rsz,vsz,tsiz,command | grep perl
>         47907 13476 13960  656 perl -d u
>
>     uname -a
>         FreeBSD fedde.littleton.co.us 4.4-RC FreeBSD 4.4-RC #16: Sat Aug 18
>         13:46:32 MDT 2001
>         [EMAIL PROTECTED]:/home/usr.obj/home/usr.src/sys/FEDDE  i386

If you want to test memory GTop is a killer (if you can get libgtop
compiled on your platform :(

On linux (ker-2.2.19/libc-5.3.12/def malloc) it releases only a part of
the allocated memory (about a half?):

% perl
use GTop;
my $gtop = GTop->new;
print "before ",  GTop::size_string($gtop->proc_mem($$)->rss), "\n";
my $large_string = "a" x 5_000_000;
print "normal ",  GTop::size_string($gtop->proc_mem($$)->rss), "\n";
my $large_string1  = eval ' "a" x 5_000_000 ';
print "eval   ",  GTop::size_string($gtop->proc_mem($$)->rss), "\n";

before  2.2M
normal 11.7M
eval   16.5M

(this is with 5.6.1 and similar with 5.7.1)


_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Reply via email to