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?
Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.