memory leaks in perl

Stewart C. Russell scruss-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org
Sun May 2 01:58:27 UTC 2004


Rick Delaney wrote:
> 
> undef($scalar) frees the memory used by $scalar.

Yes, but UTFM ;-)

> $scalar = undef will leave $scalar using lots of memory if it was
> previously using lots of memory.

True, but that memory won't be made available to the system, only to the 
program's heap. Try this with top running in another window:

$ perl -wle '$|=1; $a=undef; print "I am small"; sleep 10; $a = "foo" x 
10000000; print "I am large"; sleep 10; $a=undef; print "I am small 
again"; sleep 10;'

On my machine, my free memory drops by about 58MB when it prints "I am 
large", and doesn't return that until the interpreter exits.

I seldom, if ever, know when I'm finished with individual hash key, and 
I don't think I've ever deleted a hash entry to save memory. Perl's 
memory manglement is best left to its own devices, unless you really 
know that you really know what you're doing.

But hey, I'm just a Fortran guy.

  Stewart

-- 
$,="\n";foreach(split('',"\3\3\3c>\0>c\177cc\0~c~``\0cc\177cc"))
{$a++;$_=unpack('B8',$_);tr,01,\40#,;$b[$a%6].=$_};print @b,"\n"
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list