Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Missing reference and memory leak

by glasswalk3r (Pilgrim)
on Oct 04, 2013 at 22:50 UTC ( #1056949=note: print w/ replies, xml ) Need Help??


in reply to Re: Missing reference and memory leak
in thread Missing reference and memory leak

In fact, the code:

delete $machines{+shift};

is from the original author of FSA::Rules. I just added the debug messages and the Devel::FindRef.

You were right about your guess: I moved the usage of Devel::FindRef to the scope of ListParser class and could get the message:

FSA::Rules=HASH(0x31cc818) [refcount 13] is +- referenced by REF(0x31d8740) [refcount 1], which is | the member 'machine' of HASH(0x31cc788) [refcount 1],

Later, in the DESTROY, Devel::FindRef gave me the same HASH address.

After a fair amount of time checking the code of FSA::Rules, I got this (I pasted only the interesting parts):

my (%machines, %states); sub new { my $class = shift; my $self = bless {}, $class; my $fsa = $machines{$self} = { done => undef, notes => {}, stack => [], table => {}, self => $self, }; $def->{name} = $state; $def->{machine} = $self; $fsa->{table}{$state} = $obj; push @{$fsa->{ord}}, $obj; $states{$obj} = $def;

I created a new method to loop over %machines and %states and setting the references to the FSA::Rules object to undef. and invoked it at the end of parse method from ListParser.

After that, I could finally get the object termination in the moment that I want:

freeing myself after cleanup FSA::Rules=HASH(0x214e718) [refcount 1] is referenced by REF(0x1a30bc8) [refcount 1], which is the lexical '$fsa' in CODE(0x1a30958) [refcount 3], which is the global &Siebel::Srvrmgr::ListParser::parse. finished free method destroying FSA::State=HASH(0x215a658) destroying FSA::State=HASH(0x215a550) destroying FSA::State=HASH(0x215a430) destroying FSA::State=HASH(0x215a310) destroying FSA::State=HASH(0x215a1f0) destroying FSA::State=HASH(0x215a0d0) destroying FSA::State=HASH(0x2159fb0) destroying FSA::State=HASH(0x2159e90) destroying FSA::State=HASH(0x2159d58) destroying FSA::State=HASH(0x2159c50) destroying FSA::State=HASH(0x214e910) FSA::Rules is dead freeing myself after cleanup FSA::Rules=HASH(0x215c148) [refcount 1] is referenced by REF(0x1a30bc8) [refcount 1], which is the lexical '$fsa' in CODE(0x1a30958) [refcount 3], which is the global &Siebel::Srvrmgr::ListParser::parse. finished free method destroying FSA::State=HASH(0x214e5e0) destroying FSA::State=HASH(0x214da28) destroying FSA::State=HASH(0x1a97978) destroying FSA::State=HASH(0x215bed8) destroying FSA::State=HASH(0x2130628) destroying FSA::State=HASH(0x2137b50) destroying FSA::State=HASH(0x214e508) destroying FSA::State=HASH(0x215bcf8) destroying FSA::State=HASH(0x2137a48) destroying FSA::State=HASH(0x2141cf8) destroying FSA::State=HASH(0x2127788) FSA::Rules is dead ListParser is gone End of program daemon is gone

Thanks!

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill


Comment on Re^2: Missing reference and memory leak
Select or Download Code
Re^3: Missing reference and memory leak
by davido (Archbishop) on Oct 05, 2013 at 01:38 UTC

    Am I understanding that your original usage was based on code examples from the module's POD? If those examples contribute to leaky code, you might do the community a favor by submitting a bug report for the module's POD.


    Dave

      Actually, the examples of the Pod were not quite helpful for me because I need to use the state machine to parse several lines of data. I evaluated the module in CPAN and my suggestions were to improve the Pod regarding that.

      Regarding the possible memory leak in the module itself (at least for the comments I made in this node, I'm sure they are not in my code) I had opened an issue in the respective Github account of the distribution.

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056949]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-10-01 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (40 votes), past polls