Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Not able to release memory

by davido (Archbishop)
on Mar 03, 2004 at 06:08 UTC ( #333467=note: print w/replies, xml ) Need Help??

in reply to Not able to release memory

Perl may be done using that memory for the moment, but virtually all OS's don't reclaim it. However, if you were to rebuild another data-structure that needed gobs of memory, the same memory would be reused within your current process.

Update: I should mention that if you really need to force your OS to reclaim memory, you should start looking at using exec to spawn a new process while terminating the current one. Of course you may need to figure out a solution to maintain state, but that's another discussion.


Replies are listed 'Best First'.
Re: Re: Not able to release memory
by waswas-fng (Curate) on Mar 03, 2004 at 06:41 UTC
    ++ davido, Some of the reasons that most OS will not reclaim memory very much or at all until the process exits are: Fragmentation -- are the small chunks of memory released valuable to other applications? If so does the OS have to restructure and virtualize the memory so that the free blocks are contiguous? At what cost?

    Unix processes tend to live in two forms, quick running (ls, cat, du) and long running (syslog, inetd, oracle). For quick running processes the process will be over soon enough and the memory free issue is moot. For long running processes the process will generally need to alloc more memory anyways, may as well make it easy and quick by leaving it for the next alloc. This happens at little expense to your physical RAM as while that memory is freed the chunk can be swapped out and used by other applications.

    You will see that on most modern unices that large block (one alloc, one free) tend to be reabsorbed by the OS -- although for instance on Solaris with an app compiled with gcc you will not see this. it all depends on the OS, the compiler and the libraries used. Not really a perl issue.

Re^2: Not able to release memory
by Anonymous Monk on Oct 15, 2004 at 16:59 UTC
    In my case, I have Tk application running in Win32 environment that never exits. Some of my variables get very large data and as a result - after a period of time, my application "eats" the memory of Windows, and windows complain that the virtual memory is too low. Most of the time - as a result of this - the application gets destroyed by Windows. What I recently found is that if one click with the mouse on the Minimize button of the Tk window, Windows is claiming back the unused memory from perl and everything goes back to normal. For example: from 128MB wperl.exe in the memory, the process size goes to 2MB. Then it starts growing again - until next time you minimize the window. So what I was thinking is that there must be an API call that identifies the process and ask the OS to require the garbige. Correct me if I am wrong. I saw this happens with many applications in Windows. I am desperate for solution about this - because I need to finish my project :(( any help is welcome. Thanks!!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://333467]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2018-06-20 23:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.