glasswalk3r has asked for the wisdom of the Perl Monks concerning the following question:
Greetings monks,
I found that my program (which is supposed to run for a long time) is leaking memory at each iteration it executes. I have already checked that by monitoring memory consumption by the process, by using Devel::Gladiator and Devel::FindRef.
Devel::Gladiator shows that my FSA::Rules instances are not being terminated as expected. I also added debug messages to the DESTROY method with syswrite to check if the object's are being terminated in the expected order. Here is what I got by running my test script:
$ perl t/DaemonHeavyLeak.t ListParser is gone End of program daemon is gone FSA::Rules=HASH(0x2faeea8) [refcount 2] is +- referenced by REF(0x2fa6ea8) [refcount 1], which is | not found anywhere I looked :( +- referenced by REF(0x27a1578) [refcount 1], which is the lexical '$self' in CODE(0x27978b8) [refcount 4], which is the global &FSA::Rules::DESTROY. FSA::Rules=HASH(0x2faeea8) [refcount 1] is referenced by REF(0x2fa6ea8) [refcount 1], which is not found anywhere I looked :( FSA::Rules is dead FSA::Rules=HASH(0x2e7a198) [refcount 2] is +- referenced by REF(0x2e7a768) [refcount 1], which is | not found anywhere I looked :( +- referenced by REF(0x27a1578) [refcount 1], which is the lexical '$self' in CODE(0x27978b8) [refcount 4], which is the global &FSA::Rules::DESTROY. FSA::Rules=HASH(0x2e7a198) [refcount 1] is referenced by REF(0x2e7a768) [refcount 1], which is not found anywhere I looked :( FSA::Rules is dead
Here is the testing code that I used:
use warnings; use strict; use Siebel::Srvrmgr::Daemon::Heavy; use Cwd; use File::Spec; use Scalar::Util qw(weaken); my $repeat = 3; my $daemon = Siebel::Srvrmgr::Daemon::Heavy->new( { gateway => 'whatever', enterprise => 'whatever', user => 'whatever', password => 'whatever', server => 'whatever', bin => File::Spec->catfile( getcwd(), 'srvrmgr-moc +k.pl' ), use_perl => 1, is_infinite => 0, timeout => 0, commands => [ Siebel::Srvrmgr::Daemon::Command->new( command => 'list comp', action => 'Dummy' ) ] } ); for ( 1 .. $repeat ) { $daemon->run(); } syswrite STDOUT, "End of program\n";
And the modified DESTROY of FSA::Rules:
sub DESTROY { my $self = shift; use Devel::FindRef; use Scalar::Util qw(weaken); syswrite STDOUT, Devel::FindRef::track $self; weaken($self); delete $machines{+shift}; syswrite STDOUT, Devel::FindRef::track $self; syswrite STDOUT, "FSA::Rules is dead\n" }
The correct order of messages of termination should be:
- FSA:Rules
- ListParser
- The program itself
- daemon
The thing is, at each execution of run(), a new FSA::Object is kept in memory unit program termination.
Besides, the message from Devel::FindRef:
+- referenced by REF(0x2e7a768) [refcount 1], which is | not found anywhere I looked :(
leaves me without hope to find what is happening.
There is anything else that I could do to detect where in the code this reference is being kept?
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Missing reference and memory leak
by chromatic (Archbishop) on Oct 04, 2013 at 18:40 UTC | |
by glasswalk3r (Friar) on Oct 04, 2013 at 22:50 UTC | |
by davido (Cardinal) on Oct 05, 2013 at 01:38 UTC | |
by glasswalk3r (Friar) on Oct 06, 2013 at 01:06 UTC |