Re: Need help with leaks

Re: Need help with leaks

am 18.12.2007 23:03:50 von Joost Diepenmaat

Abble writes:

> Okay, I have about 6,000 lines of Perl code, which generally work
> GREAT, but I have a big memory leak.
>
> Yes, I had to do some sloppy coding to leak memory in Perl. I have a
> LOT of global variables.
> After each pass of the program a few hundred megabytes get leaked into
> various variables.

I always think of a memory leak as allocating memory and then losing
the references to it so you *can't* free it anymore. Forgetting to empty
out some variable that's still accessible is not a leak. Other people
may disagree.

> I HAVE added a sub to reset everything to '' and (), but I must be
> forgetting a few variables, as on each pass the memory usage goes UP
> and UP and UP, until it gets to about 1.6GB and everything crashes.

AFAIK setting variables to '' and () doesn't necessarily reclaim any
memory to perl. undef VARIABLE may work better. But it looks like the
real problem is elsewhere.

You may have some circular structures, which will never get reclaimed
until the perl interpreter exits.

http://search.cpan.org/~lds/Devel-Cycle-1.07/lib/Devel/Cycle .pm

> Is there some way to view ALL of the Perl symbol tables and see what
> I'm forgetting to trash?

There's stuff at http://search.cpan.org/search?query=devel+leak&mode=all
and http://search.cpan.org/search?query=devel&mode=all

This one looks interesting:

http://search.cpan.org/~cgautam/Devel-DumpSizes-0.01/lib/Dev el/DumpSizes.pm

HTH,
Joost.