Fellow Monks
I discovered what I assumed to be a memory leak in an application I am writing using CGI::Application as a base. Initially I blamed my OO style - believing that some references were circular but this turned out to be untrue (I think).

The problem arises when using CGI::Application to return data to the browser. I used the following as a method to deliver images.

sub getimage { my $self = shift; my $stuff = shift; # Set the correct header $self->header_props( -type=>$stuff->{mime} ); open ( IMAGE , $stuff->{image} ) or die "Screaming $!"; return join '', <IMAGE>; }

Which functioned beautifully (once PodMaster slapped some sense into me regarding returning scalars to CGI:Application) however my httpd processes grew at an alarming rate. For every 1Mb image served , httpd grows by a larger amount.


Clean startup
  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
18388 root      15   0  2848 2848  2736 S     0.0  0.5   0:00 httpd
18389 vvr       18   0  2836 2836  2716 S     0.0  0.5   0:00 httpd
18390 vvr       18   0  2836 2836  2716 S     0.0  0.5   0:00 httpd

After serving one 6.2Mb image
  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
18388 root      15   0  2848 2848  2736 S     0.0  0.5   0:00 httpd
18389 vvr       15   0 31940  31M  2372 S     0.0  6.2   0:00 httpd
18390 vvr       18   0  2836 2836  2716 S     0.0  0.5   0:00 httpd

The resident memory size has grown from under 3Mb to over 31Mb. Almost 5 times the size of the data actually served. I am most curious to hear from anyone who has experienced similar behaviour (with CGI::Application especially).

This is occuring on a RH7.3 system, using apache1.3.26 and mod_perl 1.27. Below is the smallest case that exhibits this behaviour.

#!/usr/bin/perl -w # foo.pm , to be executed by Apache package foo; use strict; use base 'CGI::Application'; use CGI::Carp; sub handler { warn "## handler"; my $request = shift; my $app = foo->new(); $app->run(); exit; } sub setup { warn "## setup"; my $self = shift; $self->run_modes( start=>'start' ); } sub start { warn "## start"; my $self = shift; open ( FH , '/path/to/some/image' ) or confess $!; $self->header_props( -type=>'your/mimetype' ); return join '' , <FH>; } 1;

httpd.conf
PerlModule Apache PerlModule foo <Location /testleak/> SetHandler perl-script PerlHandler foo </Location>

If you've solved this before, or think you can see where I have done something bass-ackwards please let me know.


Many Thanks -
toaster.

I can't believe it's not psellchecked

In reply to CGI::Application + mod_perl =|!= memory leak by submersible_toaster

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.