Hello fellow monks!

Now that my mod_perl processes are gowing to more than 60mb each, I´m trying to clean up averything I can. Well, it used to be 100mb each, and by eliminating some unused modules I could reduce ir drastically.

But now I´m stucked in the problem of the process memory usage growing big during its lifetime. I have no public variables, and everything is OO. There is some packages which recieves big HTML strings which are latter printed to the browser. Sometimes I can have a 1mb HTML output or even more.

This packages are destroyed by the end of the session, wich is handled by a mod_perl handler (not a cgi file).

I´m doing something like:

sub handler {
 my $r = shift;
 my $page = new Html::page;
 $page->{html} = '...and here it goes...';
 $page->end(); # Does some final processing
 print "Content-type:...".
       $page->{html};
 undef $page;
}
This "end" sub is very simple, and looks like:
sub end {
 my $class = shift;
 $class->{html} = "Header" . $class->{html} . "Footer";
}
Apache2::Satus says it´s consumes about 27kb before serving a request. But, after being executed, it grows to the size of the HTML it processed (109kb in the example below).

BEFORE serving a request I get:

Memory Usage for package Html::page
Totals: 68703 bytes, 67.09 Kb, 0.07 Mb | 1284 OPs
end                 27748 bytes | 573 OPs
new                  7045 bytes | 146 OPs
And AFTER serving a request I get:

Memory Usage for package Html::page
Totals: 151779 bytes, 148.22 Kb, 0.15 Mb | 1284 OPs
end                 109244 bytes | 573 OPs
new                   7045 bytes | 146 OPs
Obviously the mod_perl process grows in the same rate, and it never releases memory. So I end up sometimes with process that grows from 62mb to 120mb in just one request.

Am I doing something wrong? Acording to my knowledge, Perl should release the memory used in the $page->{html} variable just after I undef $page or simply do $page->{html} = ''; Or maybe I´m wrong?

By the way: Linux Fedora 6 with Perl 5.8.8, Apache 2.2.3, mod_perl 2.0.2.

Thanks a lot for your attention monks!

Deigo de Lima

In reply to Memory usage of a "sub" in mod_perl by diego_de_lima

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.