http://qs321.pair.com?node_id=11116652


in reply to Perl Memory problem ...

Perl won't release memory back to the operating system at runtime, only on global destruction as the script terminates. However, Perl will re-use the memory that it has allocated and that it is no longer using. For example, if you declare a lexical variable in one scope and load it up with 30MB of data, but then let that variable fall out of scope, Perl should be able to re-use that memory space.

Places to look:


Dave

Replies are listed 'Best First'.
Re^2: Perl Memory problem ...
by eyepopslikeamosquito (Archbishop) on May 10, 2020 at 20:38 UTC

    Perl won't release memory back to the operating system at runtime, only on global destruction as the script terminates.
    While that may be true for most practical purposes, I believe Perl simply defers to the implementation of the user-level malloc function - see for example: Memory is not released back to operating system.

    Last time I looked, both Linux and Windows malloc do return "large" chunks back to the OS.

      Thanks. I was probably misremembering Tim Bunce's YAPC talk: https://www.youtube.com/watch?v=GIIeOntmojg. I'll have to review it again when I have a moment. Your research looks thorough, though.

      Update: At about 4:10 Tim discusses malloc behavior, and suggests that larger allocations are mmapped, and the gist seems to be that while rare for malloc to actually give back, it is more likely for those larger mmapped chunks. So, thanks for motivating me to find that talk again. I'll have to watch the rest of it again this evening. It does confirm your assertion, too.


      Dave