Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Perl releasing memory back to the system

by Joost (Canon)
on Apr 07, 2005 at 17:25 UTC ( [id://445801]=note: print w/replies, xml ) Need Help??


in reply to Perl releasing memory back to the system

AFAIK, perl 5.8.6 (and probably a couple of earlier versions) can release memory back to the system on Linux.

#!/usr/local/bin/perl -w use strict; $|=1; { my $string; for (1 .. 100000) { $string .= ('x' x 1000); } print "press enter to release"; <>; undef $string; # note that memory does not get released # if the variable only goes out of scope. # you *need* to undef it! } print "ok, press enter to exit"; <>;

This takes up roughly a 100 Mb on my machine, and almost all of it gets released after the first enter. (according to top, at least)

perl -V Summary of my perl5 (revision 5 version 8 subversion 6) configuration: Platform: osname=linux, osvers=2.6.8.20050102, archname=i686-linux
uname='linux sepia 2.6.8.20050102 #1 sun jan 2 14:47:32 cet 2005 i +686 gnulinux ' config_args='-DDEBUGGING -DLEAKTEST' hint=previous, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultipl +icity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include + -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-g -DDEBUGGING -DLEAKTEST', cppflags='-fno-strict-aliasing -pipe -I/usr/local/include -fno-str +ict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_O +FFSET_BITS=64 -fno-strict-aliasing -pipe -I/usr/local/include -D_LARG +EFILE_SOURCE -D_FILE_OFFSET_BITS=64' ccversion='', gccversion='3.3.5 (Debian 1:3.3.5-8)', gccosandvers= +'' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl. +a gnulibc_version='2.3.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING USE_LARGE_FILES Built under linux Compiled at Mar 15 2005 20:40:51 @INC: /usr/local/lib/perl5/5.8.6/i686-linux /usr/local/lib/perl5/5.8.6 /usr/local/lib/perl5/site_perl/5.8.6/i686-linux /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl

Replies are listed 'Best First'.
Re^2: Perl releasing memory back to the system
by zentara (Archbishop) on Apr 07, 2005 at 20:00 UTC
    Thanks! Great example, works for me. It is the first time I've seen this demonstrated with Perl. :-)

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://445801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-06-19 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.