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


in reply to memory usage and leakage

A few things to think about:

  1. Do you have a memory leak, or do you simply have memory consumption?   Test::Memory::Cycle is a good way to determine if you have self-referential data structures in a program.   (See also the other CPAN modules which it uses.)
  2. Is there memory pressure?   (If there isn’t, then the point-of-view of the always lazy operating system will be, “always room for one more!”   And, it is absolutely correct.)   The metrics produced by commands such as ps are only the roughest of indicators.   What you are really interested in is paging, particularly page steals, which is the actual indicator that something actually hurts.   If you don’t have pain, you don’t have a problem.
  3. Don’t guess ... measure.   If you suspect that excessive memory consumption is the root cause of your problem, demonstrate it.
  4. “Chips are cheap” now, whereas time is as expensive as ever.   I’m not talking about computer time here ... I’m talking about your own.   Sometimes the very best way to construct a program is to use the strongest software tools you can, then deal with any memory issues that actually develop (don’t borrow trouble ...) by “throwing silicon at it.”   After all, it’s only sand ...