> Digging deeper I found that the module in question initialized a > package variable when the module was loaded. I moved the code into a > BEGIN block and the memory usage dropped.
Looking at your test case, it seems like simply loading that module from startup.pl would do the job. The thing that I've seen improved by moving it into a BEGIN is automatic accessor methods. When I have some code that defines accessors when they're called, I change it so that it defines them up front in a BEGIN. That improves sharing (assuming they are actually used). > Of course, this begs the question, why doesn't Perl free up the memory > of code placed inside modules? There's been discussion before about why Perl doesn't free memory used by lexicals. It does get re-used the next time the lexical is used, and you can clear it with undef. I think this is in the Guide, and you can find more info in the list archives. Doug had a good post on the subject, as I recall. - Perrin