atticboy1 has asked for the wisdom of the Perl Monks concerning the following question:

I have written an app in apache asp, which uses embedded perl in the asp pages. I have realized...after I have finished the project, that the pages allocate memory from the server, even after you close the pages. As I go to my webpages, the memory used grows and grows, even if it is the same page I am accessing. I was wondering if by using strict or using lexical variables would solve these issues, or if there was another way to deallocate the memory from the perl variables. An example...my first page, makes my httpd process jump from 11 MB to 12 MB, when viewing memory usage in "top"(linux). The second page I access, jumps memory usage up to 22MB. Each page after that, continues to increase memory usage. Before I put this into a true production environment, I need to figure out why the memory is being held. Any answers or suggestions are appreciated!

Replies are listed 'Best First'.
Re: Memory Issue
by dws (Chancellor) on May 31, 2003 at 04:51 UTC
    I need to figure out why the memory is being held. Any answers or suggestions are appreciated!

    Start with what you know leaks, then start chopping pieces out of it until the leak stops. The last thing you chopped is a likely culprit. If you notice that the leakage decreases, you might have multiple culprits.

    In a "normal" script, POD directives are a great way to chop stuff out without really removing it. E.g.,

    =for DEBUGGING my @big = ('foo') x 100000000; =cut
    removes that line of code, as far as the compiler is concerned.

    Since you're using PerlScript, you might need to comment lines out. I don't know if PerlScript can cope with POD.

      Do you know if this is a common issue? Where memory is holding onto the variable contents? If so, do you have to use strict, and declare the variables as local variables? The application is fairly complex, in that it access a db, and brings in multiple arrays of info. This is the largest app I have written in perl, and have never been concerned with memory usage until now, but 22 MB for one httpd process seems a wee bit high to me.
        Do you know if this is a common issue? Where memory is holding onto the variable contents?

        You might have one or more variables that have becomes persistently global as a consequence of using ASP. Convert everything you can to a lexical variables.

        Without seeing your code, it's hard to get more specific.

Re: Memory Issue
by chromatic (Archbishop) on May 31, 2003 at 05:59 UTC

    If you aren't using lexical variables, that may be your culprit. Do you have a global array or a hash that is updated on every page load?