Need help with leaks

A

Abble

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 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.

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

I tried several of the hints on the net, including peeking at keys
\main::, and so on, but all I see there are barewords and some sub
names, none of my variable names.


Any hints appreciated.
 
J

Joost Diepenmaat

Abble said:
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/Devel/DumpSizes.pm

HTH,
Joost.
 
J

John W. Krahn

Abble said:
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 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.

perldoc -f reset


John
 
S

Spiros Denaxas

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.


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 are right, in the vast majority of cases it doesn't.

http://perldoc.perl.org/perlfaq3.html#How-can-I-make-my-Perl-program-take-less-memory?

Spiros
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,208
Messages
2,571,079
Members
47,682
Latest member
TrudiConna

Latest Threads

Top