http://www.perlmonks.org?node_id=1056949


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