Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: demonstrate that perl can give back memory to the OS

by Joost (Canon)
on Feb 27, 2009 at 17:05 UTC ( [id://746955]=note: print w/replies, xml ) Need Help??


in reply to demonstrate that perl can give back memory to the OS

Simple example:
sub ps { system("/bin/ps", "-o", "pid,size,vsize", $$); } ps(); { my $x = " " x 2_000_000; ps(); undef $x; } ps();
This is perl, v5.10.0 built for i686-linux-thread-multi

Replies are listed 'Best First'.
Re^2: demonstrate that perl can give back memory to the OS
by ikegami (Patriarch) on Feb 27, 2009 at 17:30 UTC

    An explanation:

    Lexical (my) variables and their string (or array) buffers aren't deallocated on scope exit whenever possible, only cleared. undef $var; (but not $var = undef;) deallocates the variable's string buffer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-23 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found