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


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