Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: memory "release" with $#=-1

by eXile (Priest)
on Jun 28, 2005 at 16:05 UTC ( [id://470691]=note: print w/replies, xml ) Need Help??


in reply to memory "release" with $#=-1

afaik, the memory that you'll free if a var is going out of scope is never released back to the OS, so perl keeps the memory allocated for future use within the script.

In other words, the memory is free to reuse by the same perl process, but not for other processes on your system.

I've tested this using these 3 simple scripts, and you can see doing a ps -o vsz,command | grep perl (or similar type of command, adapt to your OS, in my case it's FreeBSD), that in the first 2 cases the memory usage by the relevant perl processes is the same:

#!/usr/bin/perl use strict; # case 1: array uses a lot of memory, and goes out of scope $0 = "highmemusage_going_out_of_scope"; { my @aap = map { $_ * $_ } ( 0 .. 100000 ); } sleep 300;
#!/usr/bin/perl use strict; # case 2: array uses a lot of memory, and stays in scope $0 = "highmemusage_staying_in_scope"; my @aap = map { $_ * $_ } ( 0 .. 100000 ); sleep 300;
#!/usr/bin/perl use strict; # case 3: use as baseline mem usage of your perl $0 = "reference"; sleep 300;
Anybody more familiar with perl memory allocation please correct me if I'm wrong,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-04-19 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found