Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: memory usage woes

by lhoward (Vicar)
on Nov 20, 2001 at 23:47 UTC ( #126594=note: print w/replies, xml ) Need Help??

in reply to memory usage woes

When a variable goes out of scope, perl frees up memory for use by other purposes within your program, but perl never releases memory to the OS (not until your program ends).

Replies are listed 'Best First'.
Re: Re: memory usage woes
by urufu-san (Novice) on Nov 21, 2001 at 00:56 UTC
    I feared as much. Maybe I'll write this thing in C after all..

      C doesn't return freed virtual memory back to the operating system either. Unless you are running out of swap space, this shouldn't be of much concern, however.

      Now, Perl certainly uses more memory than most things. But avoiding Perl because some number that "top" reports that you don't even understand very well might not be the best application of your time. (:

      The two most common measure of memory use are roughly "virtual memory size" and "working set size". The first measures (roughly) how much swap space a process requires while it exists. The second measures (roughly) how much physical memory the process requires to actually get work done.

      These days, if you are worried about running out of swap space, then I strongly suggest you configure more swap space for your system.

      If you are worried about your system running slow (because it wants more physical memory), then you need to look at the working set size, and that size will go down when the process stops using the memory that it still has allocated to its virtual address space (whether the program was written in C or in Perl).

      If you want a process to return memory to the operating system, then you pretty much have to restart the program. You can do that easily in Perl with: exec( $^X, $0, @ARGV );

              - tye (but my friends call me "Tye")
        But, if you follow tye's advice about "exec", keep in mind that (perldoc -f exec):

        Note that `exec' will not call your `END' blocks, nor will it call any `DESTROY' methods in your objects.

        To avoid weird surprises for long-running programs, I usually let them end "manually" after a period of time and then start/restart them with an endless loop in a shell or batch script.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2019-08-24 00:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found