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

Re: Depth First Search through Digraph Results in Memory Leak

by Hofmator (Curate)
on Jan 08, 2004 at 15:07 UTC ( #319816=note: print w/replies, xml ) Need Help??


in reply to Depth First Search through Digraph Results in Memory Leak

Yes, like ysth says, this looks like a bug in perl. A workaround here is to change the sub transitive_closure_DFS like this:

sub transitive_closure_DFS { my ($self, $node) = @_; my $nodes = []; my $search = sub { push @$nodes, $_[0] }; $self->DFS($node, $search); my @nodes = @$nodes; $nodes = ''; return [@nodes]; }

So it seems that somehow the anonymous array in $nodes is not properly destroyed automatically. But how this is related to the recursiveness dependency ysth mentions escapes me ...

Update
I've written a follow-up with a simplified version of the problem (and an additional segfault :) here.

-- Hofmator

Replies are listed 'Best First'.
Re: Re: Depth First Search through Digraph Results in Memory Leak
by djantzen (Priest) on Jan 08, 2004 at 20:40 UTC

    Well I'll be damned, that fixes it. I've changed $nodes = '' to undef $nodes with the same results. So for some reason perl needs to be told to destroy the array when it should take a cue from the lexical going out of scope. I'll prepare a bug report after I stop sighing in relief. Thank you Hofmator!


    "The dead do not recognize context" -- Kai, Lexx

      Change those print calls to warn(). I'm guessing that those arrays are kept around because the closures were kept around and that both were eventually cleaned up during global destruction. You are always free to clear a variable with prejudice - use undef as a function. undef $nodes might give you some different results. (you already did that. Whoops).

      That may still be a bug though but whether it is in the reference counting of $nodes' array or $sub's clusure I don't know. But then it isn't clear to me that it is a bug.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://319816]
help
Chatterbox?
[Corion]: Yay. I've now published (at $work) that random Excel workbook where on one sheet you enter your SQL and on the other sheet, you have a button and receive the results. I'm so evil in enabling cow-orkers to self-supply ;)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2018-07-18 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (392 votes). Check out past polls.

    Notices?