Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Depth First Search through Digraph Results in Memory Leak

by Hofmator (Curate)
on Jan 08, 2004 at 15:07 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://319816]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found