> I have a couple of questions regarding leaking memory in mod_perl: > > 1. What are the main culprits, in order of severity, of memory leaks, i.e.: > > a. global variables (NOT lexically scoped via my) > b. ... > c. ... > > 2. When writing code from scratch (a new application), what is the best > way to avoid creating leaks to begin with, i.e., use strict;, PerlWarn On, > etc.. ?
There are actually not very many ways you can leak memory in Perl (and thus mod_perl). Most people confuse memory growth with memory leakage. If you want to know how to avoid memory growth, look at the performance tuning stuff in the Guide, like passing references, avoiding slurping of large files, controlling the buffering of DBI result sets, etc. Leaks are caused by circular references, the string form of eval (at least it used to leak a little), nested closures (sometimes created accidentally with the Error module), and one or two obscure syntax problems. I think one of them involved code like "my $x = 7 if $y;". Matt Sergeant got bitten by this in the early stages of AxKit development, and the details are in the mailing list archive. Global variables by themselves are not a source of leaks or growth. If you slurp a large file into a global, your process will grow, but the same is true for a lexical. - Perrin