Finding a Perl memory leak

前端 未结 3 1015
难免孤独
难免孤独 2020-12-19 07:07

SOLVED see Edit 2

Hello,

I\'ve been writing a Perl program to handle automatic upgrading of local (proprietary) programs (for the company I

相关标签:
3条回答
  • 2020-12-19 07:30

    How do you know that it's a memory leak? I can think of many other reasons why the OS would kill a program.

    The first question I would ask is "Does this program always work correctly from the command line?". If the answer is "No" then I'd fix these issues first.

    On the other hand if the answer is "Yes", I would investigate all the differences between having the program executed under cron and from the command line to find out why it is misbehaving.

    0 讨论(0)
  • 2020-12-19 07:36

    If it is run by cron, that shouldn't it die after iteration? If that is the case, hard for me to see how a memory leak would be a big deal...

    Are you sure it is the script itself, and not the child processes that are using the memory? Perhaps it ends up creating a real lot of ssh sessions , instead of doing a bunch of stuff in one session?

    0 讨论(0)
  • 2020-12-19 07:38

    You could try using Devel::Size to profile some of your objects. e.g. in the main:: scope (the .pl file itself), do something like this:

    use Devel::Size qw(total_size);
    
    foreach my $varname (qw(varname1 varname2 ))
    {
        print "size used for variable $varname: " . total_size($$varname) . "\n";
    }
    

    Compare the actual size used to what you think is a reasonable value for each object. Something suspicious might pop out immediately (e.g. a cache that is massively bloated beyond anything that sounds reasonable).

    Other things to try:

    • Eliminate bits of functionality one at a time to see if suddenly things get a lot better; I'd start with the use of any external libraries
    • Is the bad behaviour localized to just one particular machine, or one particular operating system? Move the program to other systems to see how its behaviour changes.
    • (In a separate installation) try upgrading to the latest Perl (5.10.1), and also upgrade all your CPAN modules
    0 讨论(0)
提交回复
热议问题