Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: reducing memory usage

by chromatic (Archbishop)
on Dec 17, 2002 at 03:44 UTC ( #220440=note: print w/replies, xml ) Need Help??


in reply to reducing memory usage

Sorry, it's hard to diagnose this without seeing code. You do have a few options though.

First, make sure that your variables are scoped properly. Don't keep them around longer than you need them. If you have global hashes or arrays, make sure they're not continually growing. Leave your program running for a while and make sure its memory usage doesn't keep growing. Use the Devel::Size module to check the size of suspicious data structures.

Replies are listed 'Best First'.
Re: Re: reducing memory usage
by batkins (Chaplain) on Dec 17, 2002 at 11:09 UTC
    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.
      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?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2019-09-23 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (274 votes). Check out past polls.

    Notices?