http://www.perlmonks.org?node_id=220490


in reply to Re: reducing memory usage
in thread reducing memory usage

Here's the strange thing: my memory usage actually decreases over time. It starts at around 13 or 14 meg and then in maybe ten minutes, it drops to 8 meg.

Replies are listed 'Best First'.
Re: Re: Re: reducing memory usage
by Elian (Parson) on Dec 17, 2002 at 15:56 UTC
    Are you sure it's total memory used and not just in-core memory? You might be seeing some of your unused pages swapped out to disk. If so, that's usually a sign you've got garbage that's not getting cleaned up, either because of circular data structures, or you (or perl) isn't disposing of something used earlier on.

    If you really are seeing a footprint shrink like that, it's likely you've got something being cached somewhere that gets reused after a while and shrinks on that reuse. (Perl does some aggressive caching of array structures in lexicals, for example)

    Finally, it's possible you're running afoul of an almost-but-not-quite empty memory segment. Perl's asked for a 5 meg chunk at some point, uses it and then frees up all but a few bytes right at the beginning, so it has to hold on to the chunk until the last thing using a part of it dies or goes somewhere else. (And there's not much you can do about that, unfortunately)

      Hmm, in the Task Manager on Windows XP, I see 13 megs. Does this include swapped-out pages?
        Enable all the memory columns in the task manager and see. (You could do that with Win2K, so I assume XP will as well) Someone else'll have to say for sure with that info--I don't have a win box around to check.