Very tricky, I think, that bugs---yes more than one was needed... I think I'll give a little bit of pseudo code:
There is a forking server (no mod_perl, but same idea) called 'god', it watches the process table for new entries. When it finds one, it fork()s into a runner class. The single parameter for the runner is the database row (#1). The runner creates a $self, thaw()s the process (class man) from a BLOB and starts it. The process will be able to call back the runner to do some work (same idea as $r in mod_perl, again), e.g. save it's state. After the process has ended (maybe with an exception, or because it was killed or commanded to take a nap), the runner will clear all local variables to trigger all DESTROY()s of all objects that the process might have created (#2).class god; method fork_kids { my $row = $db->find_new_process_table_entries(); if (not fork()) { my $runner = runner->new($row); #1 $runner->run(); } } class runner; method new { $self->{row} = shift; } method run { $man = thaw $self->{row}->{column}; $man->run($self); %{$man} = %{$self} = (); #2 exit(); } method saveState() { my $state = shift; $db->saveState( nfreeze($state) ); $self->{row}->{state} = $state; #3 } class man { method run { my $mom = shift; while ($alive) { $mom->saveState($state); ... } }
Now, there are 2 problems: First, see code #1: The runner gets the database row as array ref and saves that into $self later. Outch, $p will never go out of scape before exit(). This would not be a problem, as $row should only contain strings from the database, but: #3 the second bug. Here the saveState() method tries to hold the row in self in sync with the database. But, oops, it saves the real object, not the frozen one. And it is saved into the imortal $row.
And so all objects that were part of the state lived much longer than they should.
Yes, we rely on DESTROY() to clean up some objects' database "shadow". One very big reason: We also use exceptions. That's it.
I knew the createon time and place of all objects. I knew every single object in my test case. I just could not figure out why the did not die when I killed the "man" object, and I was really puzzled when I "killed" the state object... ;)
In reply to Re: Help me to find hidden object references....
by Beechbone
in thread Help me to find hidden object references....
by Beechbone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |