When I had to deal with a problem like this I found the information from Devel::Leak rather useful. For tracking down objects I hacked up something like this to use to find where I was allocating objects that never went away:
package Leaker; use Data::Dumper; $Data::Dumper::Indent = 1; %CLASS; *CORE::GLOBAL::bless = sub { my $obj = shift; my $class = shift || caller(); if (exists $CLASS{$obj}) { delete $CLASS{$obj}; } $obj = CORE::bless($obj, $class); if ($class =~ /ObjClass/ or (caller())[1] =~ /file|names|here/) { # print "$obj created\n"; $CLASS{$obj} = join "\n\t", map {join ":", caller($_)} 1; } $obj; }; sub UNIVERSAL::DESTROY { my $obj = shift; if (exists $CLASS{$obj}) { # print "$obj destroyed\n"; delete $CLASS{$obj}; } } sub Leaked { print Dumper(\%CLASS); } 1;
It worked for me. That won't work for classes which have a DESTROY method of their own. (You could just choose to replace those methods on the fly with a wrapper, much like Dominus does with Memoize.) That also won't help much if your memory leak is at the C level. (Which it well could be.)

If all else fails you can just restart yourself with:

exec($0, @ARGV);
But personally I would be strongly inclined to have the process hold a lock while it is running, and then have a periodic cron job that starts the job if it is not currently running. A big advantage of that approach is that if you have an unexpected shutdown of the process (eg a machine reboot) then nobody has to remember to start your process again. (This is a classic Unix mistake. Someone writes a daemon that is key to their process, launches it, doesn't document, then 6 months later there is a reboot and nobody knows how to get it running again.)

In reply to Re (tilly) 1: any way to control a memory leak by tilly
in thread any way to control a memory leak by rdww

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.