Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 ...

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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2018-10-15 22:07 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (82 votes). Check out past polls.